#include <bits/stdc++.h>
using namespace std;
void debug(){cerr<<"\n";}
template <typename H, typename... T>
void debug(H h, T... t) {cerr<<h; if (sizeof...(t)) cerr << ", "; debug(t...);}
#define deb(x) cerr<<#x<<" = ";debug(x);
bool cmp(int x, int y) {
return x > y;
}
void solve()
{
int n,k;
cin >> n >> k;
vector <int> vec(n);
for(int &i : vec) {
cin >> i;
}
sort(vec.begin(), vec.end(), cmp);
int last = vec[k-1];
int ans = k;
for(int i = k; i < n;i++) {
if(last == vec[i])
ans++;
}
cout << ans;
}
int main()
{
ios::sync_with_stdio(false); cin.tie(nullptr);
int tt = 1;
//cin >> tt;
for(int case_num = 1; case_num <= tt; case_num++){
//cout << "Case #" << case_num << ": ";
solve();
cout << "\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 37 38 39 40 41 42 43 | #include <bits/stdc++.h> using namespace std; void debug(){cerr<<"\n";} template <typename H, typename... T> void debug(H h, T... t) {cerr<<h; if (sizeof...(t)) cerr << ", "; debug(t...);} #define deb(x) cerr<<#x<<" = ";debug(x); bool cmp(int x, int y) { return x > y; } void solve() { int n,k; cin >> n >> k; vector <int> vec(n); for(int &i : vec) { cin >> i; } sort(vec.begin(), vec.end(), cmp); int last = vec[k-1]; int ans = k; for(int i = k; i < n;i++) { if(last == vec[i]) ans++; } cout << ans; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int tt = 1; //cin >> tt; for(int case_num = 1; case_num <= tt; case_num++){ //cout << "Case #" << case_num << ": "; solve(); cout << "\n"; } return 0; } |
English