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 <iostream>
using namespace std;
using ll = long long;
ll* a;
bool cmp(int i, int j)
{
if(a[i] != a[j]) return a[i] < a[j];
else return i < j;
}
const ll INF = 1'000'000'000'000'000'000LL;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, q;
cin >> n >> q;
a = new ll[1+n+1];
for(int i = 1; i <= n; i++) cin >> a[i];
a[0] = a[n+1] = 0;
for(int j = 1; j <= q; j++)
{
ll l, r, x;
cin >> l >> r >> x;
for(int i = l; i <= r; i++)
a[i] += x;
ll dp[1+n];
dp[0] = 0;
ll mx1 = -INF, mx2 = -INF;
for(int i = 1; i <= n; i++)
{
mx1 = max(mx1, dp[i-1] - a[i]);
mx2 = max(mx2, dp[i-1] + a[i]);
dp[i] = max(mx1 + a[i], mx2 - a[i]);
}
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... |