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
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n,d;
cin >> n >> d;
vector<int> arr(n+1);
for(int i=1;i<=n;i++)cin>>arr[i];
int q;
cin >> q;
for(int i=1;i<=q;i++){
int l,r;cin>>l>>r;
vector<int> curr(n+1);
for(int x=l;x<=r;x++){
curr[x] = curr[x-1]+((d+(arr[x]%d)-(curr[x-1]%d))%d);
}
int uses = 1e15;
int ans = 0;
bool works = true;
for(int x=r;x>=l;x--){
int req = (arr[x]-curr[x])/d;
if(req<0)works=false;
uses = min(uses,req);
ans+=req-uses;
}
if(works)cout<<ans<<'\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... |