This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |