제출 #1135962

#제출 시각아이디문제언어결과실행 시간메모리
1135962RandomUserSjeckanje (COCI21_sjeckanje)C++20
55 / 110
35 ms3652 KiB
#include <bits/stdc++.h> #define ar array //#define int long long using namespace std; using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll>; const int mod = 1e9 + 7; const int LOG = 20; const int maxn = 1e5 + 5; ll dp[maxn][2]; signed main() { ios_base::sync_with_stdio(false); cout.tie(0); cin.tie(0); int n, q; cin >> n >> q; vector<ll> a(n+1); for(int i=1; i<=n; i++) cin >> a[i]; while(q--) { ll l, r, x; cin >> l >> r >> x; for(int i=l; i<=r; i++) a[i] += x; for(int i=0; i<=n; i++) dp[i][0] = dp[i][1] = -1e18; dp[1][0] = dp[1][1] = 0; for(int i=2; i<=n; i++) { dp[i][0] = max(dp[i-1][0], dp[i-1][1]); dp[i][1] = max(dp[i-1][0], dp[i-1][1]); if(a[i-1] <= a[i]) dp[i][0] = max(dp[i][0], dp[i-1][0] + a[i] - a[i-1]); if(a[i-1] >= a[i]) dp[i][1] = max(dp[i][1], dp[i-1][1] + a[i-1] - a[i]); } cout << max(dp[n][0], dp[n][1]) << '\n'; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...