#include <iostream>
#include <list>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;
int main(int argc, char** argv) {
int n, k;
std::list<int> a;
int punkty;
int ile=0, min_punktow=-1;
cin >> n >> k;
for (int i=0; i<n; ++i)
{
cin >> punkty;
a.push_back(punkty);
}
a.sort();
a.reverse();
for(std::list<int>::iterator it = a.begin(); it!=a.end(); it++)
{
++ile;
if(ile<k){
// cout << "ile<k" << ile << endl;
}
else if(ile==k){
min_punktow = *it;
// cout << "ile=k" << ile << endl;
}
else if(ile>k && min_punktow==*it)
{
// cout << "ile>k, =min" << ile << endl;
}
else{
--ile;
break;
}
}
cout << ile << endl;
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 <iostream> #include <list> /* run this program using the console pauser or add your own getch, system("pause") or input loop */ using namespace std; int main(int argc, char** argv) { int n, k; std::list<int> a; int punkty; int ile=0, min_punktow=-1; cin >> n >> k; for (int i=0; i<n; ++i) { cin >> punkty; a.push_back(punkty); } a.sort(); a.reverse(); for(std::list<int>::iterator it = a.begin(); it!=a.end(); it++) { ++ile; if(ile<k){ // cout << "ile<k" << ile << endl; } else if(ile==k){ min_punktow = *it; // cout << "ile=k" << ile << endl; } else if(ile>k && min_punktow==*it) { // cout << "ile>k, =min" << ile << endl; } else{ --ile; break; } } cout << ile << endl; return 0; } |
English