Advertisement
vlatkovski

Izbori [електронски '10] (NEDOVRSENO)

Oct 1st, 2017
318
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.84 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5.     int n; cin >> n;
  6.     multiset<int> g;
  7.     int f; cin >> f;
  8.  
  9.     for (int i = 1; i < n; ++i) {
  10.         int x; cin >> x;
  11.         if (x >= f) {
  12.             g.insert(x);
  13.         }
  14.     }
  15.     int c = 0;
  16.     vector<multiset<int>::iterator> removeit;
  17.     while (!g.empty() && *g.rbegin() > f) {
  18.         for (multiset<int>::iterator it = g.begin(); it != g.end(); ++it) {
  19.             f++;
  20.             c++;
  21.             if (*it - c < f) {
  22.                 removeit.push_back(it);
  23.             }
  24.         }
  25.         while (!removeit.empty()) {
  26.             cout << "removing " << *removeit[0] << " because " << *removeit[0] << "-" << c << "(c) < " << f << "(f)\n";
  27.             g.erase(removeit[0]);
  28.             removeit.erase(removeit.begin());
  29.         }
  30.     }
  31.  
  32.     cout << c << endl;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement