#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using ll = long long; using Pll = pair; using Pii = pair; constexpr ll MOD = 1000000007; constexpr long double EPS = 1e-10; constexpr int dyx[4][2] = { { 0, 1}, {-1, 0}, {0,-1}, {1, 0} }; constexpr int MAX_N = 200000; template class LazyRMQ { public: int n; T inf = INT_MAX; vector data, lazy; LazyRMQ(int m, T init_value=0){ // 2のべき乗にする n = 1; while(n < m) n <<= 1; data.assign(2*n-1, init_value); lazy.assign(2*n-1, 0); inf = init_value; } void eval(int k, int kl, int kr){ if(data[k] == inf) data[k] = 0; if(lazy[k] == 0) return; data[k] += lazy[k]; if(kr - kl > 1){ lazy[2*k+1] += lazy[k]; lazy[2*k+2] += lazy[k]; } lazy[k] = 0; } // [s,t) void add(int s, int t, T x, int k, int kl, int kr){ eval(k, kl, kr); if(kr <= s || t <= kl) return; if(s <= kl && kr <= t){ lazy[k] += x; eval(k, kl, kr); return; } int kc = (kl+kr)/2; add(s, t, x, 2*k+1, kl, kc); add(s, t, x, 2*k+2, kc, kr); data[k] = max(data[2*k+1], data[2*k+2]); } void add(int s, int t, T x) { add(s, t, x, 0, 0, n); } // [s,t) T find(int s, int t, int k, int kl, int kr){ eval(k, kl, kr); if(kr <= s || t <= kl) return inf; if(s <= kl && kr <= t) return data[k]; int kc = (kl+kr)/2; T vl = find(s, t, 2*k+1, kl, kc); T vr = find(s, t, 2*k+2, kc, kr); return max(vl, vr); } T find(int s, int t) { return find(s, t, 0, 0, n); } }; int main() { int n; cin >> n; vector a(n+1); LazyRMQ tree(n+3); // [t-23, t] の和 for(int i=1;i<=n;++i){ cin >> a[i]; tree.add(i, min(n+1, i+24), a[i]); } int q, t; ll v; cin >> q; for(int i=0;i> t >> v; ll v_diff = v - a[t]; tree.add(t, min(t+24, n+1), v_diff); cout << tree.find(0, n+1) << endl; } }