#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+2),pr(n+1);
vector <int> b(n+1),r(n);
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
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;
| ^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
16 ms |
604 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1918 ms |
4100 KB |
Output is correct |
2 |
Correct |
2939 ms |
4288 KB |
Output is correct |
3 |
Correct |
1787 ms |
4692 KB |
Output is correct |
4 |
Correct |
1797 ms |
4148 KB |
Output is correct |
5 |
Correct |
2223 ms |
4168 KB |
Output is correct |
6 |
Execution timed out |
4065 ms |
10012 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
4064 ms |
9756 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
16 ms |
604 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |