Tranvick

Untitled

Jul 9th, 2013
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.93 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <algorithm>
  4.  
  5. using namespace std;
  6.  
  7. const int N = 111111;
  8. int a[N], n, x, k, ans;
  9.  
  10. int main() {
  11.     scanf("%d%d%d", &n, &x, &k);
  12.     for (int i = 0; i < n; ++i)
  13.         scanf("%d", &a[i]);
  14.     if (x == 0) {
  15.         long long s = 0;
  16.         for (int i = 0; i < a[i]; ++i) s += a[i];
  17.         cout << (s + k - 1) / k << endl;
  18.         return 0;
  19.     }
  20.     for(;;) {
  21.         int ok = 0;
  22.         for (int i = 0; i < n && !ok; ++i)
  23.             if (a[i] > 0) ok = 1;
  24.         if (!ok) break;
  25.         ++ans;
  26.         ok = 0;
  27.         for (int i = 0; i < n; ++i)
  28.             if (a[i] >= x) {
  29.                 a[i] -= x;
  30.                 ok = 1;
  31.                 break;
  32.             }
  33.         if (!ok) {
  34.             int t = max_element(a, a + n) - a;
  35.             a[t] = 0;
  36.         }
  37.         ok = k;
  38.         for (int i = 0; i < n && ok; ++i)
  39.             while (a[i] % x && ok) {
  40.                 --a[i];
  41.                 --ok;
  42.             }
  43.         for (int i = 0; i < n && ok; ++i) {
  44.             if (a[i] <= 0) continue;
  45.             int t = min(ok, a[i]);
  46.             ok -= t;
  47.             a[i] -= t;
  48.         }
  49.     }
  50.     cout << ans << endl;
  51.     return 0;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment