Submission #940588

#TimeUsernameProblemLanguageResultExecution timeMemory
940588SamNguyenSjeckanje (COCI21_sjeckanje)C++14
15 / 110
2049 ms2616 KiB
#include <bits/stdc++.h> using namespace std; template <class T1, class T2> inline bool minimise(T1 &x, T2 y) { if (x > y) { x = y; return true; } return false; } template <class T1, class T2> inline bool maximise(T1 &x, T2 y) { if (x < y) { x = y; return true; } return false; } const int MAX = 2e5 + 7; int N, Q; long long arr[MAX]; void input() { cin >> N >> Q; for (int i = 1; i <= N; i++) cin >> arr[i]; } void init() { } void update(int l, int r, long long x) { for (int i = l; i <= r; i++) arr[i] += x; } long long dp[MAX]; long long get() { dp[0] = 0; for (int i = 1; i <= N; i++) { long long min_v = arr[i], max_v = arr[i];; dp[i] = dp[i - 1]; for (int j = i; j > 0; j--) { minimise(min_v, arr[j]); maximise(max_v, arr[j]); maximise(dp[i], dp[j - 1] + max_v - min_v); } } return dp[N]; } int main(void) { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); input(); init(); while (Q--) { int l, r; cin >> l >> r; long long x; cin >> x; update(l, r, x); cout << get() << '\n'; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...