#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; #define ST first #define ND second #define SIZE(a) ((int)a.size()) int main() { ios_base::sync_with_stdio(0); int n, k; cin >> n >> k; vector<int> a(n); for(int &a_i : a) { cin >> a_i; } sort(a.begin(), a.end()); reverse(a.begin(), a.end()); for(int i=k; i < n; i++) { if(a[i] == a[i-1]) { k++; } else { break; } } cout << k << "\n"; }
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 | #include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; #define ST first #define ND second #define SIZE(a) ((int)a.size()) int main() { ios_base::sync_with_stdio(0); int n, k; cin >> n >> k; vector<int> a(n); for(int &a_i : a) { cin >> a_i; } sort(a.begin(), a.end()); reverse(a.begin(), a.end()); for(int i=k; i < n; i++) { if(a[i] == a[i-1]) { k++; } else { break; } } cout << k << "\n"; } |