# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
870139 | nghia0912 | Sjeckanje (COCI21_sjeckanje) | C++17 | 1 ms | 348 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.
#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 = 0;
for (int i = 1; i <= n; ++i){
dp[i] = max({dp[i -1 ], a[i] - minndp, maxxdp - a[i]});
minndp = min(minndp, a[i] - dp[i - 1]);
maxxdp = max(maxxdp, dp[i - 1] + a[i]);
// cout << dp[i] << " ";
//cout << i << " " << dp[i] << " " << minndp << " " << maxxdp << endl;
}
// cout << 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
*/
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... |