# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1110166 | lamlamjjdo | Fish 3 (JOI24_fish3) | C++17 | 1298 ms | 4936 KiB |
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];
main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
if(fopen("c.INP","r")){
freopen("c.INP","r",stdin);
freopen("c.OUT","w",stdout);
}
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';
}
}
Compilation message (stderr)
# | 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... |