제출 #984674

#제출 시각아이디문제언어결과실행 시간메모리
984674blackavarSjeckanje (COCI21_sjeckanje)C++14
55 / 110
2029 ms13156 KiB
#include <bits/stdc++.h> using namespace std; long long n, a[1000005], d[1000005], q, dp[1000005]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> q; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i < n; i++) d[i] = a[i] - a[i + 1]; dp[0] = 0; while (q--) { long long l, r, x; cin >> l >> r >> x; d[l - 1] -= x; d[r] += x; d[0] = d[1]; for (int i = 1; i < n; i++) { if (d[i] * d[i - 1] > 0) dp[i] = max(dp[i - 1], dp[i - 1] + abs(d[i])); else dp[i] = max(dp[i - 1], dp[i - 2] + abs(d[i])); } cout << dp[n - 1] << "\n"; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...