#include <bits/stdc++.h>
using namespace std;
void s(int tab[],int left,int right)
{
int i=left;
int j=right;
int x=tab[(left+right)/2];
do
{
while(tab[i]<x) i++;
while(tab[j]>x) j--;
if(i<= j)
{
swap( tab[i],tab[j]);
i++;
j--;
}
} while(i<=j);
if(left<j) s(tab,left,j);
if(right>i) s(tab,i,right);
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
short n,k,odp=0;
cin>>n>>k;
int a[n];
for(int i=0;i<n;i++) cin>>a[i];
s(a,0,n-1);
for(int i=0;i<n-k;i++) if(a[i]>=a[n-k]) odp++;
odp+=k;
cout<<odp;
return 0;
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | #include <bits/stdc++.h> using namespace std; void s(int tab[],int left,int right) { int i=left; int j=right; int x=tab[(left+right)/2]; do { while(tab[i]<x) i++; while(tab[j]>x) j--; if(i<= j) { swap( tab[i],tab[j]); i++; j--; } } while(i<=j); if(left<j) s(tab,left,j); if(right>i) s(tab,i,right); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); short n,k,odp=0; cin>>n>>k; int a[n]; for(int i=0;i<n;i++) cin>>a[i]; s(a,0,n-1); for(int i=0;i<n-k;i++) if(a[i]>=a[n-k]) odp++; odp+=k; cout<<odp; return 0; } |
English