#include <iostream>
#include <algorithm>
using namespace std;
int pkt[2005];
int aplayers, mint;
bool abc;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> aplayers >> mint;
for (int i = 0; i < aplayers; i++) {
cin >> pkt[i];
}
sort(pkt, pkt + aplayers);
abc = true;
if (mint != 1) {
while (abc) {
if (pkt[aplayers - mint] != 0) {
if (pkt[aplayers - mint] == pkt[aplayers - mint - 1]) {
while (pkt[aplayers - mint] == pkt[aplayers - mint - 1]) {
mint++;
abc = false;
}
}
else if (pkt[aplayers - mint] != pkt[aplayers - mint - 1]) {
aplayers--;
}
}
else {
aplayers--;
continue;
}
}
}
else if (mint == 1) {
while (abc) {
if (pkt[aplayers - mint] != 0) {
if (pkt[aplayers - mint + 1] == pkt[aplayers - mint]) {
while (pkt[aplayers - mint + 1] == pkt[aplayers - mint]) {
mint++;
abc = false;
}
}
else if (pkt[aplayers - mint + 1] != pkt[aplayers - mint]) {
aplayers--;
}
}
else {
aplayers--;
continue;
}
}
}
cout << mint << 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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | #include <iostream> #include <algorithm> using namespace std; int pkt[2005]; int aplayers, mint; bool abc; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> aplayers >> mint; for (int i = 0; i < aplayers; i++) { cin >> pkt[i]; } sort(pkt, pkt + aplayers); abc = true; if (mint != 1) { while (abc) { if (pkt[aplayers - mint] != 0) { if (pkt[aplayers - mint] == pkt[aplayers - mint - 1]) { while (pkt[aplayers - mint] == pkt[aplayers - mint - 1]) { mint++; abc = false; } } else if (pkt[aplayers - mint] != pkt[aplayers - mint - 1]) { aplayers--; } } else { aplayers--; continue; } } } else if (mint == 1) { while (abc) { if (pkt[aplayers - mint] != 0) { if (pkt[aplayers - mint + 1] == pkt[aplayers - mint]) { while (pkt[aplayers - mint + 1] == pkt[aplayers - mint]) { mint++; abc = false; } } else if (pkt[aplayers - mint + 1] != pkt[aplayers - mint]) { aplayers--; } } else { aplayers--; continue; } } } cout << mint << endl; } |
English