Submission #950049

# Submission time Handle Problem Language Result Execution time Memory
950049 2024-03-20T04:09:20 Z vjudge1 Sjeckanje (COCI21_sjeckanje) C++17
55 / 110
2000 ms 3580 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define size(x) (int)x.size()
#define all(x) x.begin(), x.end()

template<class S, class T>
bool chmin(S& a, const T& b) {
  return a > b ? (a = b) == b : false;
}
template<class S, class T>
bool chmax(S& a, const T& b) {
  return a < b ? (a = b) == b : false;
}

signed main() {
  cin.tie(nullptr)->sync_with_stdio(false);
  int n, q; cin >> n >> q;
  int a[n + 1];
  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;
    }
    vector<int> dp(n + 1, 0);
    int max_b = a[1], max_s = -a[1];
    for (int i = 2; i <= n; ++i) {
      dp[i] = max(max_s + a[i], max_b - a[i]);
      chmax(dp[i], dp[i - 1]);
      chmax(max_s, dp[i - 1] - a[i]);
      chmax(max_b, dp[i - 1] + a[i]);
    }
    cout << dp[n] << '\n';
  }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 33 ms 348 KB Output is correct
8 Correct 32 ms 344 KB Output is correct
9 Correct 32 ms 348 KB Output is correct
10 Correct 32 ms 348 KB Output is correct
11 Correct 32 ms 512 KB Output is correct
12 Correct 36 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 33 ms 348 KB Output is correct
8 Correct 32 ms 344 KB Output is correct
9 Correct 32 ms 348 KB Output is correct
10 Correct 32 ms 348 KB Output is correct
11 Correct 32 ms 512 KB Output is correct
12 Correct 36 ms 344 KB Output is correct
13 Execution timed out 2039 ms 3580 KB Time limit exceeded
14 Halted 0 ms 0 KB -