#include <iostream> #include <algorithm> using namespace std; int t[2010]; int main(){ ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0); int n,k; cin >> n >> k; for(int i = 0; i < n; i++) cin >> t[i]; sort(t,t + n); int i = n - 1; while(i >= 0 && (i >= n - k || t[i] == t[i+1])) i--; cout << n - i - 1 << endl; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | #include <iostream> #include <algorithm> using namespace std; int t[2010]; int main(){ ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0); int n,k; cin >> n >> k; for(int i = 0; i < n; i++) cin >> t[i]; sort(t,t + n); int i = n - 1; while(i >= 0 && (i >= n - k || t[i] == t[i+1])) i--; cout << n - i - 1 << endl; } |