#include <iostream> #include <vector> #include <algorithm> using namespace std; int main() { int n, k, m, totalk; totalk = 0; vector<int> numbers; cin >> n >> k; for (int i = 0; i < n; ++i){ cin >> m; numbers.push_back(m); } sort(numbers.begin(), numbers.end(), greater<int>()); int lastn = numbers[0]; for (int i = 0; i < n; ++i) { if (k <= 0 && numbers[i] != lastn) { cout << totalk << endl; break; } // cout << numbers[i] << endl; k--; totalk++; lastn = numbers[i]; if (totalk == n) { cout << totalk << endl; break; } } 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 | #include <iostream> #include <vector> #include <algorithm> using namespace std; int main() { int n, k, m, totalk; totalk = 0; vector<int> numbers; cin >> n >> k; for (int i = 0; i < n; ++i){ cin >> m; numbers.push_back(m); } sort(numbers.begin(), numbers.end(), greater<int>()); int lastn = numbers[0]; for (int i = 0; i < n; ++i) { if (k <= 0 && numbers[i] != lastn) { cout << totalk << endl; break; } // cout << numbers[i] << endl; k--; totalk++; lastn = numbers[i]; if (totalk == n) { cout << totalk << endl; break; } } return 0; } |