#include <iostream> using namespace std; int main() { int n, k, j; cin >> n >> k; int counter = 0; int points[n]; int best[k] = {0}; for(int i = 0; i < n; i++) { cin >> points[i]; j = 0; while(j < k) { if(points[i] > best[j]) { j++; } else break; } if(j > 0) { for(int move = 0; move < j - 1; move++) best[move] = best[move + 1]; best[j - 1] = points[i]; } } for(int i = 0; i < n; i++) { if(points[i] == best[0]) counter++; } cout << k + counter - 1; 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 | #include <iostream> using namespace std; int main() { int n, k, j; cin >> n >> k; int counter = 0; int points[n]; int best[k] = {0}; for(int i = 0; i < n; i++) { cin >> points[i]; j = 0; while(j < k) { if(points[i] > best[j]) { j++; } else break; } if(j > 0) { for(int move = 0; move < j - 1; move++) best[move] = best[move + 1]; best[j - 1] = points[i]; } } for(int i = 0; i < n; i++) { if(points[i] == best[0]) counter++; } cout << k + counter - 1; return 0; } |