# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
392671 | Mamnoon_Siam | Sjeckanje (COCI21_sjeckanje) | C++17 | 2068 ms | 428 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;
using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;
#define all(v) begin(v), end(v)
#define sz(v) (int)(v).size()
#define fi first
#define se second
const int N = 3003;
int n, q;
ll a[N], dp[N];
int main(int argc, char const *argv[])
{
#ifdef LOCAL
freopen("in", "r", stdin);
#endif
scanf("%d %d", &n, &q);
for(int i = 1; i <= n; ++i) {
scanf("%lld", &a[i]);
}
while(q--) {
int l, r, x;
scanf("%d %d %d", &l, &r, &x);
for(int i = l; i <= r; ++i)
a[i] += x;
for(int i = n; i >= 1; --i) {
dp[i] = max(a[i] - a[n], a[n] - a[i]);
for(int j = i+1; j <= n; ++j) {
dp[i] = max(dp[i], dp[j] + a[i] - a[j-1]);
dp[i] = max(dp[i], dp[j] + a[j-1] - a[i]);
}
}
printf("%lld\n", dp[1]);
}
return 0;
}
/*
* use std::array instead of std::vector, if u can
* overflow?
* array bounds
*/
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... |