#include #include #include #include #include #include #include #include #include #define REP(i, n) for (int i = 0; i < (n); i++) #define FOR(i, init, n) for (int i = init; i < (n); i++) #define ALL(obj) (obj).begin(), (obj).end() #define RALL(obj) (obj).rbegin(), (obj).rend() #define Cout(obj) cout << obj << endl #define Size(obj) (int)(obj).size() #define fcout cout << fixed << setprecision(10) #define fi first #define se second using namespace std; using ll = long long int; using P = pair; using T = tuple; using edge = struct { int to, cost; }; const int MOD = 1e9 + 7; const int iINF = 1e9; const long long int llINF = 1e18; const double PI = acos(-1.0); const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; template struct LazzySegTreeMax { private: ll N = 1; vector node, lazy; public: LazzySegTreeMax(vector vec) { ll size = Size(vec); while (N < size) { N *= 2; } node.resize(2 * N - 1); lazy.resize(2 * N - 1, 0); REP(i, size) { node[i + N - 1] = vec[i] + (size - i) * 3; } for (int i = N - 2; 0 <= i; i--) { node[i] = max(node[2 * i + 1], node[2 * i + 2]); } } void eval(int k, int l, int r) { if (lazy[k] != 0) { node[k] += lazy[k]; if (r - l > 1) { lazy[2 * k + 1] += lazy[k]; lazy[2 * k + 2] += lazy[k]; } lazy[k] = 0; } } void add(int a, int b, T value, int k = 0, int l = 0, int r = -1) { if (r < 0) r = N; eval(k, l, r); if (r <= a || b <= l) return; if (a <= l && r <= b) { lazy[k] += value; eval(k, l, r); } else { add(a, b, value, 2 * k + 1, l, (l + r) / 2); add(a, b, value, 2 * k + 2, (l + r) / 2, r); node[k] = max(node[2 * k + 1], node[2 * k + 2]); } } T getMax(int a, int b, int k = 0, int l = 0, int r = -1) { if (r < 0) { r = N; } eval(k, l, r); if (r <= a || b <= l) { return -iINF; } if (a <= l && r <= b) { return node[k]; } T vl = getMax(a, b, 2 * k + 1, l, (l + r) / 2); T vr = getMax(a, b, 2 * k + 2, (l + r) / 2, r); return max(vl, vr); } }; int main() { cin.tie(0); ios::sync_with_stdio(false); int N; cin >> N; vector T(N - 1); REP(i, N - 1) { cin >> T[i]; } int M; cin >> M; vector L(M), R(M), D(M); REP(i, M) { cin >> L[i] >> R[i] >> D[i]; } LazzySegTreeMax seg(T); REP(i, M) { seg.add(L[i] - 1, R[i], D[i]); Cout(seg.getMax(0, N)); } return 0; }