#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, q; cin >> n >> q;
  int a[n]; for (int i = 0; i < n; i++) cin >> a[i];
  while (q--) {
    int x, b, c; cin >> x >> b >> c;
    x--; b--;
    for (int i = x; i <= b; i++) a[i] += c;
    int dp[n];
    for (int i = 0; i < n; i++) dp[i] = 0;
    for (int i = 1; i < n; i++) {
      int largest = a[i];
      int smallest = a[i];
      for (int j = i-1; j >= 0; j--) {
        largest = max(largest, a[j+1]);
        smallest = min(smallest, a[j+1]);
        dp[i] = max(dp[i], dp[j]+largest-smallest);
      }
      largest = max(largest, a[0]);
      smallest = min(smallest, a[0]);
      dp[i] = max(dp[i], largest-smallest);
    }
    cout << dp[n-1] << '\n';
  }
}
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |