제출 #1132483

#제출 시각아이디문제언어결과실행 시간메모리
1132483lopkusSjeckanje (COCI21_sjeckanje)C++20
55 / 110
2093 ms3608 KiB
#include <bits/stdc++.h> #define int long long using namespace std; signed main() { ios::sync_with_stdio(false); cin.tie(0); int n, q; cin >> n >> q; vector<int> a(n + 1); for(int i = 1; i <= n; i++) { cin >> a[i]; } while(q--) { int l, r, x; cin >> l >> r >> x; for(int i = l; i <= r; i++) { a[i] += x; } vector<int> dp(n + 1, 0); int best1 = a[1]; int best2 = - a[1]; for(int i = 1; i <= n; i++) { dp[i] = max({dp[i - 1], best1 - a[i], best2 + a[i]}); best1 = max(best1, dp[i - 1] + a[i]); best2 = max(best2, dp[i - 1] - a[i]); } cout << dp[n] << "\n"; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...