#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 524288;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
ll d;
cin >> n >> d;
vector<ll> oc(n);
for (auto & x: oc) {
cin >> x;
}
int q; cin >> q;
while (q--) {
int ql, qr;
cin >> ql >> qr;
ql--; qr--;
ll last = (1LL << 41);
ll ans = 0;
for (int i = qr; i >= ql; --i) {
if (oc[i] <= last) {
last = oc[i];
} else {
ll ops = ((oc[i] - last) + d - 1) / d;
ans += ops;
last = oc[i] - ops * d;
}
}
cout << (last < 0LL ? -1 : ans) << '\n';
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |