#include <iostream> #include <vector> #include <algorithm> using namespace std; int main() { int n, k; vector <int> v; cin >> n >> k; for (int i=0; i<n; i++) { int m; cin >> m; v.push_back(m); } sort(v.begin(), v.end()); for (int i=n-k-1; i>=0; i--) if (v[i]!=v[i+1]) break; else k++; cout << k; }
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 | #include <iostream> #include <vector> #include <algorithm> using namespace std; int main() { int n, k; vector <int> v; cin >> n >> k; for (int i=0; i<n; i++) { int m; cin >> m; v.push_back(m); } sort(v.begin(), v.end()); for (int i=n-k-1; i>=0; i--) if (v[i]!=v[i+1]) break; else k++; cout << k; } |