Submission #1118908

#TimeUsernameProblemLanguageResultExecution timeMemory
1118908ZflopSjeckanje (COCI21_sjeckanje)C++14
0 / 110
3 ms340 KiB
#include <bits/stdc++.h> using namespace std; const int NMAX = 3 * (int)1e5; int N,Q,A[NMAX]; void solve() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> N >> Q; for (int i = 1; i <= N;++i) cin >> A[i]; for (int q = 1; q <= Q;++q) { vector<vector<int>>dp(N + 1,vector<int>(2)); int l,r,k; cin >> l >> r >> k; for (int i = l; i <= r;++i) A[i] += k; int ans = 0; dp[1][0] = -A[1]; dp[1][1] = A[1]; for (int i = 2; i <= N;++i) { dp[i][0] = max({dp[i - 1][0] + A[i - 1],dp[i - 1][1] - A[i - 1]}) - A[i]; dp[i][1] = max({dp[i - 1][0] + A[i - 1],dp[i - 1][1] - A[i - 1]}) + A[i]; if (A[i] >= A[i - 1]) dp[i][0] = max(dp[i][0],dp[i - 1][0]); if (A[i] <= A[i - 1]) dp[i][1] = max(dp[i][1],dp[i - 1][1]); } cout << max(dp[N][0] + A[N],dp[N][1] - A[N]) << '\n'; } } main() { solve(); }

Compilation message (stderr)

Main.cpp: In function 'void solve()':
Main.cpp:17:7: warning: unused variable 'ans' [-Wunused-variable]
   17 |   int ans = 0;
      |       ^~~
Main.cpp: At global scope:
Main.cpp:33:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   33 | main() {
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...