제출 #1103714

#제출 시각아이디문제언어결과실행 시간메모리
1103714sitablechairFish 3 (JOI24_fish3)C++17
9 / 100
2074 ms7612 KiB
#include <bits/stdc++.h> #define ll long long #define ldb long double #define endl '\n' #define For(i,l,r) for(int i=l;i<=r;i++) #define ForD(i,r,l) for(int i=r;i>=l;i--) #define REP(i,l,r) For(i,l,r-1) #define PER(i,r,l) ForD(i,r-1,l) #define ff first #define ss second #define pb push_back #define all(x) x.begin(),x.end() #define All(x,n) x+1,x+1+n #define Alll(x,n) x,x+n #define sz(x) (signed)x.size() #define unq(x) x.resize(unique(all(x))-x.begin()) #define mpa make_pair #ifdef NCGM #include"debug.h" #else #define debug(...) "fr"; #endif using namespace std; const int N=3e5+3; int n,q; ll d,c[N]; int main() { cin.tie(0)->sync_with_stdio(0); cin >> n >> d; For(i,1,n) cin >> c[i]; cin >> q; while(q--) { int l,r; cin >> l >> r; ll ans=0,cur=c[r]; ForD(k,r-1,l) { if (c[k]<=cur) { cur=c[k]; continue; } ll sus=(c[k]-cur)/d; while (c[k]-sus*d>cur) sus++; ans+=sus; cur=c[k]-sus*d; } if (cur>=0) cout << ans << endl; else cout << -1 << endl; } return 0; }
#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...