#include <bits/stdc++.h>
using namespace std;
int n,k,wynik[2007],result;
int main()
{
ios_base::sync_with_stdio(false);
cin >> n >> k;
for(int i=0; i<n; i++)
{
cin >> wynik[i];
}
sort(wynik, wynik+n);
int pos = n-1;
while(pos >= 0 && (result < k || wynik[pos] == wynik[pos+1]))
{
//cout << pos << ' ' << result << ' ' << wynik[pos] << ' ' << wynik[pos+1] << endl;
result++;
pos--;
}
cout << result << 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 <bits/stdc++.h> using namespace std; int n,k,wynik[2007],result; int main() { ios_base::sync_with_stdio(false); cin >> n >> k; for(int i=0; i<n; i++) { cin >> wynik[i]; } sort(wynik, wynik+n); int pos = n-1; while(pos >= 0 && (result < k || wynik[pos] == wynik[pos+1])) { //cout << pos << ' ' << result << ' ' << wynik[pos] << ' ' << wynik[pos+1] << endl; result++; pos--; } cout << result << endl; } |
English