#include <bits/stdc++.h> using namespace std; int main() { cin.tie(0); ios::sync_with_stdio(0); int numberOfContestants, shirtsToGive; cin >> numberOfContestants >> shirtsToGive; vector<int> points(numberOfContestants); for (int i = 0; i < numberOfContestants; i++) { cin >> points[i]; } sort(points.begin(), points.end(), greater<int>()); int answer = shirtsToGive; for (int i = shirtsToGive - 1; i < numberOfContestants; i++) { if (i != points.size() - 1 && points[i] == points[i + 1]) { answer++; continue; } break; } cout << answer << 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 | #include <bits/stdc++.h> using namespace std; int main() { cin.tie(0); ios::sync_with_stdio(0); int numberOfContestants, shirtsToGive; cin >> numberOfContestants >> shirtsToGive; vector<int> points(numberOfContestants); for (int i = 0; i < numberOfContestants; i++) { cin >> points[i]; } sort(points.begin(), points.end(), greater<int>()); int answer = shirtsToGive; for (int i = shirtsToGive - 1; i < numberOfContestants; i++) { if (i != points.size() - 1 && points[i] == points[i + 1]) { answer++; continue; } break; } cout << answer << endl; } |