#include<iostream> #include<vector> #include<algorithm> using namespace std; bool my(int i, int j) {return (j<i);} int main() { int n, k; cin >> n >> k; vector<int> a; for(int i=0;i<n;i++) { int x; cin >> x; a.push_back(x); } sort(a.begin(),a.end(),my); a.push_back(1000); while(a[k-1]==a[k]) k++; cout << k; 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 | #include<iostream> #include<vector> #include<algorithm> using namespace std; bool my(int i, int j) {return (j<i);} int main() { int n, k; cin >> n >> k; vector<int> a; for(int i=0;i<n;i++) { int x; cin >> x; a.push_back(x); } sort(a.begin(),a.end(),my); a.push_back(1000); while(a[k-1]==a[k]) k++; cout << k; return 0; } |