Submission #1022530

#TimeUsernameProblemLanguageResultExecution timeMemory
1022530AiperiiiDungeon 3 (JOI21_ho_t5)C++14
11 / 100
4045 ms10064 KiB
#include <bits/stdc++.h> #define int long long #define all(x) x.begin(),x.end() #define ff first #define ss second #define pb push_back using namespace std; signed main(){ int n,m; cin>>n>>m; vector <int> a(n+1),pr(n+1); vector <int> b(n+2),r(n+1); for(int i=1;i<=n;i++){ cin>>a[i]; pr[i]=pr[i-1]+a[i]; } for(int i=1;i<=n;i++){ cin>>b[i]; } stack <int> st; for(int i=1;i<=n+1;i++){ while(!st.empty() && b[st.top()]>=b[i]){ r[st.top()]=i-1; st.pop(); } st.push(i); } while(m--){ int s,t,u; cin>>s>>t>>u; bool ok=1; int en=0,ans=0,ls=-1; for(int i=s;i<t;i++){ int sum=pr[min(t-1,r[i])]-pr[i-1]; sum=max(0ll,sum-en); ans+=min(sum,u-en)*b[i]; if(min(sum,u-en)>0)ls=b[i]; en+=min(sum,u-en); en-=a[i]; if(en<0){ ok=0; } } if(ok)cout<<ans<<"\n"; else cout<<-1<<"\n"; } }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:33:24: warning: variable 'ls' set but not used [-Wunused-but-set-variable]
   33 |         int en=0,ans=0,ls=-1;
      |                        ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...