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