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;
#define int long long
signed main() {
cin.tie(nullptr)->sync_with_stdio(false);
int n, d; cin >> n >> d;
int c[n];
for (int i = 0; i < n; i++) cin >> c[i];
int q; cin >> q;
for (int i = 0; i < q; i++) {
int l, r;
cin >> l >> r;
--l; --r;
int ans = 0, prv = c[r];
for (int j = r - 1; j >= l; j--) {
int cur = c[j] - prv;
if (cur < 0) prv = c[j];
else {
int x = (cur + d - 1) / d;
ans += x;
prv = c[j] - (d * x);
}
}
if (prv < 0) cout << -1 << '\n';
else cout << 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... |