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"
#include <cstring>
#include <fstream>
using namespace std;
#define ll long long
#define forR(i, x) for(int i = 0; i < x; ++i)
#define REP(i, a, b) for(int i = (a); i < (b); ++i)
#define open(s) freopen(((string) s + ".in").c_str(), "r", stdin); freopen(((string) s + ".out").c_str(), "w", stdout)
#define all(i) i.begin(), i.end()
#define boost() cin.sync_with_stdio(0); cin.tie()
#define int ll
const int MN = 210;
int arr[MN], dp[MN];
signed main() {
int n, q; cin >> n >> q;
REP(i, 1, n + 1) cin >> arr[i];
forR(g, q){
int l, r, x; cin >> l >> r >> x;
REP(i, l, r + 1) arr[i] += x;
REP(i, 1, n + 1){
dp[i] = 0;
int ma=arr[i], mi=arr[i];
for(int j = i; j >= 1; --j){
ma=max(ma, arr[j]);
mi = min(mi, arr[j]);
dp[i] = max(dp[i], ma - mi + dp[j - 1]);
}
}
cout << dp[n] << '\n';
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |