Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdio>
- #include <algorithm>
- using namespace std;
- const int N = 111111;
- int a[N], n, x, k, ans;
- int main() {
- scanf("%d%d%d", &n, &x, &k);
- for (int i = 0; i < n; ++i)
- scanf("%d", &a[i]);
- if (x == 0) {
- long long s = 0;
- for (int i = 0; i < a[i]; ++i) s += a[i];
- cout << (s + k - 1) / k << endl;
- return 0;
- }
- for(;;) {
- int ok = 0;
- for (int i = 0; i < n && !ok; ++i)
- if (a[i] > 0) ok = 1;
- if (!ok) break;
- ++ans;
- ok = 0;
- for (int i = 0; i < n; ++i)
- if (a[i] >= x) {
- a[i] -= x;
- ok = 1;
- break;
- }
- if (!ok) {
- int t = max_element(a, a + n) - a;
- a[t] = 0;
- }
- ok = k;
- for (int i = 0; i < n && ok; ++i)
- while (a[i] % x && ok) {
- --a[i];
- --ok;
- }
- for (int i = 0; i < n && ok; ++i) {
- if (a[i] <= 0) continue;
- int t = min(ok, a[i]);
- ok -= t;
- a[i] -= t;
- }
- }
- cout << ans << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment