#include <cstdio> #include <iostream> #include <algorithm> #include <string> #include <unordered_set> #include <queue> using namespace std; int a[2000+1]; int main(){ int k = 0; int n = 0; cin >> n; cin >> k; for(int i = 0; i < n; ++i){ cin >> a[i]; } sort(begin(a),end(a),greater<int>()); //for(int i = 0; i <n; ++i){ // cout << a[i] << " "; //} int wynik = k; int i = k; while(i < n && a[i]==a[k-1]){ wynik++; i++; } cout << wynik << "\n"; 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 <cstdio> #include <iostream> #include <algorithm> #include <string> #include <unordered_set> #include <queue> using namespace std; int a[2000+1]; int main(){ int k = 0; int n = 0; cin >> n; cin >> k; for(int i = 0; i < n; ++i){ cin >> a[i]; } sort(begin(a),end(a),greater<int>()); //for(int i = 0; i <n; ++i){ // cout << a[i] << " "; //} int wynik = k; int i = k; while(i < n && a[i]==a[k-1]){ wynik++; i++; } cout << wynik << "\n"; return 0; } |