#include #include #include #include #include #include #include #include #include #include #include using namespace std; /*int p = 998244353;*/ int p = 1000000007; #define int long long #define vel vector #define vvel vector #define rep(i,n) for(int i=0;i #define qin pair #define V vector #define Endl endl #define veb vector #define sq(a) (a)*(a) #define rev(s) reverse(s.begin(),s.end()) #define end_pr(s) cout << s < q; q.push(mid1); while (!q.empty()) { int st = q.front(); q.pop(); rep(i, way[st].size()) { int to = way[st][i]; if (dist[to] == -1) { dist[to] = dist[st] + 1; q.push(to); } } } return dist; } pin most_far(int now, int n, vvel &way) { vel dist1 = dis(now, way); pin ans = mkp(-1, 0); rep(i, n) { if (dist1[i] > ans.first) { ans = mkp(dist1[i], i); } } return ans; } template V uni(V &v) { if (v.size() == 0) { return v; } sor(v); V ans(1, v[0]); for (int i = 1; i < v.size(); i++) { if (v[i] != v[i - 1]) { ans.push_back(v[i]); } } v = ans; return v; } int s_gcd(int a, int b) { if (b == 0) { return a; } return s_gcd(b, a%b); } int gcd(int a, int b) { a = abs(a); b = abs(b); if (a < b) { swap(a, b); } return s_gcd(a, b); } int solve(int sum, int lim) { if (sum <= lim) { return sum - 1; } if (sum > lim * 2) { return 0; } return lim * 2 - sum+1; } signed main() { int n; cin >> n; vel a(n); rep(i, n) { cin >> a[i]; } int mx = 0; rep(i, n - 23) { int qans = 0; rep(j, 24) { qans += a[i + j]; } mmax(mx, qans); } int q; cin >> q; rep(i, q) { int t, v; cin >> t >> v; t--; a[t] = v; int ze = 0; int low = max(ze, t - 23); int upp = min(t, n - 24); int now_sum = 0; rep(j, 24) { now_sum += a[low + j]; } mmax(mx, now_sum); for (int j = low; j < upp; j++) { now_sum -= a[j]; now_sum += a[j + 24]; mmax(mx, now_sum); } cout << mx << endl; } }