이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
const int NN = 1e6 + 5;
const int mo = 1e9 + 7;
const ld eps = 1e-9;
ll n, q, a[NN], d[3030][4], x[3030][3030];
ll depe(ll pos, ll tr)
{
if(pos > n && tr == 0)
return 0;
if(pos > n)
return -1e18;
ll &ret = d[pos][tr];
if(ret == -1)
{
ret = depe(pos + 1, tr);
if(tr == 0)
{
ret = max(ret, depe(pos + 1, 1) + a[pos]);
ret = max(ret, depe(pos + 1, 2) - a[pos]);
}
else
if(tr == 1)
ret = max(ret, depe(pos + 1, 0) - a[pos]);
else
ret = max(ret, depe(pos + 1, 0) + a[pos]);
}
return ret;
}
int main()
{
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin >> n >> q ;
for(ll i = 1; i <= n; i++)
cin >> a[i];
for(ll i = 1; i <= q; i++)
{
ll L, R, tam;
cin >> L >> R >> tam;
for(ll i = L; i <= R; i++)
a[i] += tam;
memset(d, -1, sizeof(d));
cout << depe(1, 0) << "\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... |