#include <bits/stdc++.h> using namespace std; int n, k; vector<int> v; int main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> k; for (int i = 0; i < n; i++){ int a; cin >> a; v.push_back(a); } sort(v.begin(), v.end()); reverse(v.begin(), v.end()); while (v[k] == v[k - 1]) k++; cout << k; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | #include <bits/stdc++.h> using namespace std; int n, k; vector<int> v; int main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> k; for (int i = 0; i < n; i++){ int a; cin >> a; v.push_back(a); } sort(v.begin(), v.end()); reverse(v.begin(), v.end()); while (v[k] == v[k - 1]) k++; cout << k; } |