# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
870121 | nghia0912 | Sjeckanje (COCI21_sjeckanje) | C++17 | 2033 ms | 600 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#define COPYRIGHT CODE BY TRINH TUAN NGHIA
#include<bits/stdc++.h>
#define Boost ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ll long long
#define endl "\n"
#define st first
#define nd second
#define ii pair <ll,ll>
#define iii pair <ll,ii>
#define iiii pair <ii,ii>
#define pb push_back
#define NAME "recipe"
using namespace std;
const int N = 2e5 + 10;
const int Nsub1 = 210;
const int Nsub2 = 3e3 + 10;
int n,q ;
long long dp[3010];
ll a[N];
void inp (){
cin >> n >> q;
for (int i = 1;i <= n; ++i){
cin >> a[i];
}
}
void reset(){
for (int i =1 ; i <= n; ++i)dp[i] = 0;
}
void sub1(){
while (q--){
reset();
int l, r, x;
cin >> l >> r >> x;
for (int i = l; i <= r; ++i){
a[i] += x;
}
for (int i = 1; i <= n; ++i){
ll minn = a[i];
ll maxx = a[i];
for (int j = i; j >= 1; --j){
minn = min(minn, a[j]);
maxx = max(maxx, a[j]);
dp[i] = max({dp[i], dp[j - 1] + a[i] - minn, dp[j - 1] + maxx - a[i]});
// if (i == 2 and j == 1)cout << minn << " " << maxx << "\n";
}
// cout << a[i] << " ";
}
// cout << "\n";
// for (int i =1 ; i <= n; ++i)cout << dp[i] << " ";
// cout << "\n";
cout << dp[n] << "\n";
}
}
void sub2(){
while (q--){
reset();
int l, r, x;
cin >> l >> r >> x;
for (int i = l; i <= r; ++i){
a[i] += x;
}
ll minn = 1e18;
ll maxx = 0;
ll minndp = 1e18;
ll maxxdp = -1e18;
for (int i = 1; i <= n; ++i){
dp[i] = max({dp[i], a[i] - minndp, maxxdp - a[i]});
minndp = min(minndp, a[i] - dp[i - 1]);
maxxdp = max(maxxdp, dp[i - 1] + a[i]);
//cout << i << " " << dp[i] << " " << minndp << " " << maxxdp << endl;
}
cout << dp[n] << endl;
}
}
void solve(){
sub1();
// sub2();
}
signed main (){
if (fopen(NAME".inp", "r")){
freopen(NAME".inp", "r", stdin);
freopen(NAME".out", "w", stdout);
}
Boost;
inp();
solve();
}
/*
input
*/
/*
output
*/
컴파일 시 표준 에러 (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... |