#include<cstdio> #include<algorithm> #include <bits/stdc++.h> using namespace std; int main(){ int t[2005],n,k; scanf("%d%d",&n,&k); for(int i = 0; i<n ;i++){ scanf("%d",&t[i]); } t[n]=-1; sort(t, t+n, greater<int>()); while(t[k-1]==t[k]) k++; printf("%d",k); return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | #include<cstdio> #include<algorithm> #include <bits/stdc++.h> using namespace std; int main(){ int t[2005],n,k; scanf("%d%d",&n,&k); for(int i = 0; i<n ;i++){ scanf("%d",&t[i]); } t[n]=-1; sort(t, t+n, greater<int>()); while(t[k-1]==t[k]) k++; printf("%d",k); return 0; } |