#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int n,k,t;
vector <int> punkty;
int main() {
// your code goes here
cin >> n >> k;
for (int i=0;i<n;i++)
{
cin >> t;
punkty.push_back(-t);
}
sort(punkty.begin(),punkty.end());
int baseline=punkty[k-1];
int extras=0;
for(int i=k;i<n;i++)
{
if (punkty[i]==baseline) extras++;
else break;
}
cout << k+extras;
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 | #include <iostream> #include <vector> #include <algorithm> using namespace std; int n,k,t; vector <int> punkty; int main() { // your code goes here cin >> n >> k; for (int i=0;i<n;i++) { cin >> t; punkty.push_back(-t); } sort(punkty.begin(),punkty.end()); int baseline=punkty[k-1]; int extras=0; for(int i=k;i<n;i++) { if (punkty[i]==baseline) extras++; else break; } cout << k+extras; return 0; } |
English