This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
mt19937_64 rng(time(0));
using ll = long long;
#define int long long
const int N = 2e5 + 1;
void solve() {
int n, d; cin >> n >> d;
vector<int> c(n + 1);
for (int i = 1; i <= n; ++i) {
cin >> c[i];
}
int q; cin >> q;
while (q--) {
int l, r; cin >> l >> r;
vector<int> a = c;
int res = 0;
bool bad = 0;
for (int i = r - 1; i >= l; --i) {
if (a[i] > a[i + 1]) {
int p = (a[i] - a[i + 1] + d - 1) / d;
res += p;
a[i] -= p * d;
}
if (a[i] < 0) {
bad = 1;
break;
}
}
cout << (!bad ? res : -1) << '\n';
}
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
#ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif // LOCAL
int T = 1;
while (T--) solve();
return 0;
}
# | 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... |