Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int main() {
- int N;
- cin >> N;
- vector<long long> L(N);
- for (int i = 0; i < N; i++) {
- cin >> L[i];
- }
- sort(L.begin(), L.end());
- long long opened = 0;
- int remaining = N;
- for (int i = 0; i < N && remaining > 1; i++) {
- if (opened >= remaining - 1) break;
- long long need = remaining - 1 - opened;
- long long take = min(L[i], need);
- opened += take;
- if (take == L[i]) remaining--;
- }
- cout << opened << "\n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment