답안 #920521

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
920521 2024-02-02T17:12:56 Z myst6 Sjeckanje (COCI21_sjeckanje) C++14
0 / 110
1 ms 344 KB
#include <bits/stdc++.h>

using namespace std;

// take multiple subsegments of the array, skipping element straight after
// 9 -2 3 -9 -5 -6 -7 -10 0 1 5 7 -10
// (9) - (-9 -5 -6 -7 -10) + (1 5 7)
// dp[0] => max when not taking last
// dp[1] => max score when taking last, and adding
// dp[2] => max score when taking last, and subbing
// can go from 0 => 0/1/2
//        from 1 => 1/0
//        from 2 => 2/0
// ndp[0] = max(dp[0], dp[1], dp[2])
// ndp[1] = max(dp[0], dp[1]) + diff[i]
// ndp[2] = max(dp[0], dp[2]) - diff[i]

int main() {
  cin.tie(0)->sync_with_stdio(0);
  int n, q;
  cin >> n >> q;
  vector<int> A(n);
  for (int i=0; i<n; i++) cin >> A[i];
  vector<int> diff(n);
  while (q--) {
    int l, r, x;
    cin >> l >> r >> x;
    for (int i=l-1; i<=r-1; i++) {
      A[i] += x;
    }
    for (int i=1; i<n; i++) {
      diff[i] = A[i] - A[i-1];
    }
    array<int, 3> dp;
    dp[0] = dp[1] = dp[2] = 0;
    for (int i=1; i<n; i++) {
      array<int, 3> ndp;
      ndp[0] = max({dp[0], dp[1], dp[2]});
      ndp[1] = max(dp[0], dp[1]) + diff[i];
      ndp[2] = max(dp[0], dp[2]) - diff[i];
      swap(dp, ndp);
    }
    cout << max({dp[0], dp[1], dp[2]}) << "\n";
  }
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -