Advertisement
mikhubble

Untitled

Nov 18th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.69 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <list>
  5. #include <queue>
  6.  
  7. using namespace std;
  8.  
  9. int main() {
  10.     ios_base::sync_with_stdio(false);
  11.     cin.tie(NULL);
  12.     freopen("bureaucracy.in", "r", stdin);
  13.     freopen("bureaucracy.out", "w", stdout);
  14.     int norma, n, sum = 0;
  15.     cin >> n >> norma;
  16.     vector<int> gopniki(0);
  17.     queue<int> res;
  18.     gopniki.reserve(n);
  19.  
  20.     for (int i = 0; i < n; i++) {
  21.         int x;
  22.         cin >> x;
  23.         gopniki.push_back(x);
  24.         sum += x;
  25.     }
  26.       if (sum <= norma) {
  27.           cout << -1 << endl;
  28.           return 0;
  29.       }
  30.     /*  int l = 0, r = 1000000;
  31.       while (r - l > 1) {
  32.           int middle = l - (l - r) / 2;
  33.           long long amount = 0;
  34.           for (int person:gopniki) {
  35.               amount += min(person, middle);
  36.           }
  37.           if (amount >= norma) {
  38.               r = middle;
  39.           } else {
  40.               l = middle;
  41.           }
  42.       }
  43.       long long amount = 0;
  44.       for (int person:gopniki) {
  45.           amount += (long long) min(person, l);
  46.       }
  47.       if (amount > (long long) norma) l--;*/
  48.     int curr = 0;
  49.     for (int i = 0; i < n; i++) {
  50.         int l=norma/n;
  51.         int x = gopniki[i] - l;
  52.         if (x > 0) {
  53.             res.push(gopniki[i] - l);
  54.             curr += l;
  55.         } else {
  56.             curr += gopniki[i];
  57.         }
  58.     }
  59.     norma -= curr;
  60.     for (int i = 0; i < norma; i++) {
  61.         int tmp = res.front() - 1;
  62.         res.pop();
  63.         if (tmp > 0) res.push(tmp);
  64.     }
  65.     cout << res.size() << endl;
  66.     while (res.size() > 0) {
  67.         cout << res.front() << " ";
  68.         res.pop();
  69.     }
  70.  
  71.     return 0;
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement