제출 #1278861

#제출 시각아이디문제언어결과실행 시간메모리
1278861Robert_juniorSjeckanje (COCI21_sjeckanje)C++20
0 / 110
1 ms332 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define pb push_back #define all(x) x.begin(), x.end() #define ins insert #define F first #define S second #define ld long double const int N = 1e5 + 7, mod = 1e9 + 7; int dp[N][2], a[N]; void solve(){ int n, q; cin>>n>>q; for(int i = 1; i <= n; i++){ cin>>a[i]; } while(q--){ int l, r, x; cin>>l>>r>>x; for(int i = l; i <= r; i++){ a[i] += x; } int ans = 0; for(int i = 2; i <= n; i++){ dp[i][0] = max({0ll, dp[i - 1][0] + (a[i] - a[i - 1]), dp[i - 1][1]}); dp[i][1] = max({0ll, dp[i - 1][1] + (a[i - 1] - a[i]), dp[i - 1][0]}); } cout<<max(dp[n][1], dp[n][0])<<'\n'; } } signed main(){ ios_base :: sync_with_stdio(false); cin.tie(0); //freopen("area.in", "r", stdin); //freopen("area.out", "w", stdout); int t = 1; //cin>>t; while(t--){ solve(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...