#include using namespace std; using ll = long long; using PII = std::pair; using PLL = std::pair; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep2(i, s, n) for (int i = (s); i < (int)(n); i++) int main() { #ifdef DEBUG cout << "DEBUG MODE" << endl; ifstream in("input.txt"); //for debug cin.rdbuf(in.rdbuf()); //for debug #endif int n, r, q, t, maxrain, s, left, right; cin >> n; maxrain = 0; s = 0; vector rain; rep(i, n) { cin >> r; rain.push_back(r); } rep(i, 24) { s += rain[i]; } maxrain = s; rep(i, n - 24) { s += rain[i + 24]; s -= rain[i]; maxrain = max(maxrain, s); } cin >> q; rep(i, q) { cin >> t >> r; rain[t - 1] = r; left = max(0, t - 25), right = min(n - 1, t + 25); s = 0; rep(i, 24) { s += rain[left + i]; } maxrain = max(maxrain, s); rep(i, right - left - 23) { s += rain[left + i + 24]; s -= rain[left + i]; maxrain = max(maxrain, s); } cout << maxrain << endl; } return 0; }