Advertisement
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;
- multiset<int> g;
- int f; cin >> f;
- for (int i = 1; i < n; ++i) {
- int x; cin >> x;
- if (x >= f) {
- g.insert(x);
- }
- }
- int c = 0;
- vector<multiset<int>::iterator> removeit;
- while (!g.empty() && *g.rbegin() > f) {
- for (multiset<int>::iterator it = g.begin(); it != g.end(); ++it) {
- f++;
- c++;
- if (*it - c < f) {
- removeit.push_back(it);
- }
- }
- while (!removeit.empty()) {
- cout << "removing " << *removeit[0] << " because " << *removeit[0] << "-" << c << "(c) < " << f << "(f)\n";
- g.erase(removeit[0]);
- removeit.erase(removeit.begin());
- }
- }
- cout << c << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement