제출 #1016285

#제출 시각아이디문제언어결과실행 시간메모리
1016285dpsaveslivesFoehn Phenomena (JOI17_foehn_phenomena)C++17
100 / 100
82 ms13180 KiB
#include <bits/stdc++.h> #define ll long long using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int N,Q; ll S,T; cin >> N >> Q >> S >> T; vector<ll> A(N+1),diff(N+1,0); for(int i = 0;i<=N;++i){ cin >> A[i]; if(i != 0){ diff[i] = A[i]-A[i-1]; } } ll ans = 0; for(int i = 1;i<=N;++i){ if(diff[i] > 0){ ans -= S*diff[i]; } else{ ans -= T*diff[i]; } } while(Q--){ int l,r; ll x; cin >> l >> r >> x; if(diff[l] > 0){ ans += S*diff[l]; } else{ ans += T*diff[l]; } diff[l] += x; if(diff[l] > 0){ ans -= S*diff[l]; } else{ ans -= T*diff[l]; } if(r+1 <= N){ if(diff[r+1] > 0){ ans += S*diff[r+1]; } else{ ans += T*diff[r+1]; } diff[r+1] -= x; if(diff[r+1] > 0){ ans -= S*diff[r+1]; } else{ ans -= T*diff[r+1]; } } cout << ans << "\n"; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...