#include <bits/stdc++.h> using namespace std; int wor[2000]; int main() { int n,k,ans=0; cin >> n >> k; for(int i=0;i<n;i++) { int el; cin >> el; wor[i]=-el; } sort(wor,wor+n); for(int i=k;i<n;i++) { int curr=-wor[i]; //acout << curr << '\n'; int prev=-wor[i-1]; if(prev==curr) { ans++; } else break; } cout << ans+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 27 28 29 30 | #include <bits/stdc++.h> using namespace std; int wor[2000]; int main() { int n,k,ans=0; cin >> n >> k; for(int i=0;i<n;i++) { int el; cin >> el; wor[i]=-el; } sort(wor,wor+n); for(int i=k;i<n;i++) { int curr=-wor[i]; //acout << curr << '\n'; int prev=-wor[i-1]; if(prev==curr) { ans++; } else break; } cout << ans+k; return 0; } |