#include #include #include #include using namespace std; int main() { int n; cin >> n; vector a(n); for (int &ai: a) cin >> ai; vector sum(n - 23); // sum[i] = a[i] + .. + a[i + 23] for (int i = 0; i < 24; i++) sum[0] += a[i]; for (int i = 1; i < n - 23; i++) sum[i] = sum[i - 1] - a[i - 1] + a[i + 23]; priority_queue> que; for (int i = 0; i < n - 23; i++) que.emplace(sum[i], i); int q; cin >> q; while (q--) { int t, v; cin >> t >> v; t--; int d = v - a[t]; a[t] = v; for (int i = t - 23; i <= t; i++) { if (i < 0 || i >= n - 23) continue; sum[i] += d; que.emplace(sum[i], i); } while (true) { auto p = que.top(); if (sum[p.second] == p.first) break; que.pop(); } cout << que.top().first << endl; } return 0; }