Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<string>
- #include<math.h>
- #include<algorithm>
- #include<vector>
- #include<map>
- #include<time.h>
- #include<set>
- #include<stdio.h>
- using namespace std;
- const long long ma = 10000000;
- long long i, n, k, w, v, a[110001] = { 0 }, b[110001] = { 0 }, c[110001] = { 0 }, kr, x, kra[110001] = { 0 };
- int main() {
- cin >> n >> k >> w >> v;
- for (i = 0; i < n; i++) {
- kra[i] = -1;
- cin >> a[i];
- if (a[i] >= w)
- b[i] = 1;
- if (v != 0 && b[i] != 0)
- b[i] = min(k,max(b[i], (a[i] - w) / v));
- else if (b[i] != 0)
- b[i] = min(k,i);
- b[i] = min(b[i], max(k, long long(1)));
- if (a[i] >= w)
- b[i] = max(b[i],long long(1));
- }
- kra[0] = n - 1 - b[n - 1];
- kr = kra[0];
- x = 0;
- for (i = n - 2; i >= 0; i--) {
- if (c[i] == 0)
- {
- if (kr <= i)
- c[i] = x + 1;
- else {
- while (kra[x] > i && x < n && kra[x] != -1) {
- x++;
- }
- kr = kra[x];
- if (x == n) {
- cout << -1;
- return 0;
- }
- c[i] = x + 1;
- }
- if (kra[c[i]] == -1 || kra[c[i]]>i - b[i])
- kra[c[i]] = i - b[i];
- }
- }
- cout << c[0] << "\n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement