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;
int n,d;
long long a[5000];
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >>n>>d;
for(int i=1;i<=n;i++){
cin >>a[i];
}
int q;
cin >>q;
while(q--){
int l,r;
cin >>l>>r;
long long lst=a[r];
long long c=0;
bool t=true;
for(int i=r-1;i>=l;i--){
if(a[i]>lst){
long long g=(a[i]-lst+d-1)/d;
if(a[i]<g*d){
t=false;
break;
}
lst=a[i]-g*d;
c+=g;
}
else lst=a[i];
}
if(t)cout <<c<<'\n';
else cout<<-1<<'\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... |