이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 3007;
int n, q, a[N];
ll b[N], dp[N][2];
int getSign(ll x){
if (x < 0)
return -1;
else if (x == 0)
return 0;
else
return 1;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> q;
if (max(n, q) > 3000)
return 0;
for(int i = 1; i <= n; i++)
cin >> a[i];
for(int i = 1; i < n; i++)
b[i] = a[i + 1] - a[i];
while (q--){
int l, r, x;
cin >> l >> r >> x;
if (l > 1)
b[l - 1] += x;
if (r < n)
b[r] -= x;
// cerr << "b: ";
// for(int i = 1; i < n; i++)
// cerr << b[i] << ' ';
// cerr << endl;
dp[0][0] = dp[0][1] = 0;
for(int i = 1; i < n; i++){
dp[i][0] = max(dp[i - 1][0], dp[i - 1][1]);
dp[i][1] = dp[i - 1][0] + abs(b[i]);
if (getSign(b[i - 1]) * getSign(b[i]) != -1)
dp[i][1] = max(dp[i][1], dp[i - 1][1] + abs(b[i]));
}
cout << max(dp[n - 1][0], dp[n - 1][1]) << '\n';
}
return 0;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |