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;
using lli = long long;
int main() {
int n; lli d;
cin >> n >> d;
vector<lli> cs(n);
for (lli &c: cs)
cin >> c;
int q;
cin >> q;
while (q--) {
int l, r;
cin >> l >> r;
--l; --r;
lli cnt = 0;
lli lst = cs[r];
bool ok = true;
for (int i = r - 1; i >= l; --i) {
if (cs[i] <= lst) {
lst = cs[i];
continue;
}
cnt += (cs[i] - lst + d - 1)/d;
lst = cs[i] - ((cs[i] - lst + d - 1)/d)*d;
if (lst < 0) {
ok = false;
break;
}
}
if (!ok) cout << "-1\n";
else cout << cnt << "\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... |