#include <iostream> #include <algorithm> using namespace std; int main() { unsigned int players = 0; unsigned int shirts = 0; cin >> players >> shirts; unsigned int* points = new unsigned int[players]; for (unsigned int i = 0; i < players; i++) { cin >> points[i]; } sort(points, points + players); reverse(points, points + players); unsigned int shirts_given_out = shirts; unsigned int last_value = points[shirts - 1]; unsigned int i = shirts; while (points[i] == last_value) { shirts_given_out += 1; i += 1; } cout << shirts_given_out; 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 | #include <iostream> #include <algorithm> using namespace std; int main() { unsigned int players = 0; unsigned int shirts = 0; cin >> players >> shirts; unsigned int* points = new unsigned int[players]; for (unsigned int i = 0; i < players; i++) { cin >> points[i]; } sort(points, points + players); reverse(points, points + players); unsigned int shirts_given_out = shirts; unsigned int last_value = points[shirts - 1]; unsigned int i = shirts; while (points[i] == last_value) { shirts_given_out += 1; i += 1; } cout << shirts_given_out; return 0; } |