# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
376283 | dantoh000 | Sjeckanje (COCI21_sjeckanje) | C++14 | 1 ms | 364 KiB |
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;
typedef long long ll;
int n,q;
ll a[2005];
ll dp[2005];
int main(){
scanf("%d%d",&n,&q);
for (int i = 1; i <= n; i++){
scanf("%lld",&a[i]);
}
for (int Q = 0; Q < q; Q++){
int l,r;
ll x;
scanf("%d%d%lld",&l,&r,&x);
for (int i = l ;i <= r; i++){
a[i] += x;
}
ll A = -1000000000000000000;
ll B = -1000000000000000000;
for (int i = 1; i <= n; i++){
dp[i] = max(A+a[i], B-a[i]);
A = max(A, dp[i-1]-a[i]);
B = max(B, dp[i-1]+a[i]);
//printf("%lld ",dp[i]);
}
printf("%lld\n",dp[n]);
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |