#include #include #include #include #include #include #include using namespace std; using ll = long long; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector a(n), s(n); for (int i = 0; i < n; i++) { cin >> a[i]; } int t = 0, m = 0; for (int i = 0; i < n; i++) { if (i < 24) { t += a[i]; } else { t += a[i] - a[i - 24]; } s[i] = t; m = max(m, t); } int q; cin >> q; for (int h = 0; h < q; h++) { int t, v; cin >> t >> v; t--; int d = v - a[t]; a[t] = v; for (int i = t; i < min(t + 24, n); i++) { s[i] += d; m = max(m, s[i]); } cout << m << '\n'; } return 0; }