제출 #1118909

#제출 시각아이디문제언어결과실행 시간메모리
1118909ZflopSjeckanje (COCI21_sjeckanje)C++14
55 / 110
2058 ms15860 KiB
#include <bits/stdc++.h> using namespace std; #define int long long 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(); }

컴파일 시 표준 에러 (stderr) 메시지

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