Submission #33274

#TimeUsernameProblemLanguageResultExecution timeMemory
33274huynd2001Foehn Phenomena (JOI17_foehn_phenomena)C++14
30 / 100
123 ms5300 KiB
/*huypheu 7 8 8 13 0 4 -9 4 -2 3 10 -9 1 4 8 3 5 -2 3 3 9 1 7 4 3 5 -1 5 6 3 4 4 9 6 7 -10 */ // https://oj.uz/problem/view/JOI17_foehn_phenomena #include <bits/stdc++.h> #define int long long using namespace std; int a[200007],h[200007]; signed main() { ios_base::sync_with_stdio(false); cin.tie(0); int n,q,s,t; cin >> n >> q >> s >> t; for(int i=0;i<=n;i++) { cin >> h[i]; if(i>=1) a[i]=h[i]-h[i-1]; } int ans=0; for(int i=1;i<=n;i++) { if(a[i]>0) ans-=a[i]*s; else ans-=a[i]*t; } for(int i=1;i<=q;i++) { int l,r,x; cin >> l >> r >> x; if(l!=0) { if(r!=n) { if(a[l]>0) ans+=a[l]*s; else ans+=a[l]*t; if(a[r+1]>0) ans+=a[r+1]*s; else ans+=a[r+1]*t; a[l]+=x; a[r+1]-=x; if(a[l]>0) ans-=a[l]*s; else ans-=a[l]*t; if(a[r+1]>0) ans-=a[r+1]*s; else ans-=a[r+1]*t; } else { if(a[l]>0) ans+=a[l]*s; else ans+=a[l]*t; a[l]+=x; if(a[l]>0) ans-=a[l]*s; else ans-=a[l]*t; } } else { if(r!=n) { if(a[r+1]>0) ans+=a[r+1]*s; else ans+=a[r+1]*t; a[r+1]-=x; if(a[r+1]>0) ans-=a[r+1]*s; else ans-=a[r+1]*t; } else { } } cout << ans << endl; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...