Submission #1036261

#TimeUsernameProblemLanguageResultExecution timeMemory
1036261UnforgettableplFish 3 (JOI24_fish3)C++17
9 / 100
2071 ms7440 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...