#include using namespace std; #define REP(i,n) for(int i = 0; i < (int)(n); ++i) typedef long long ll; struct BIT{ vector bit; int n; //1-indexed BIT(){init();} BIT(int n):n(n){init();} void init(){ bit.clear(); bit.resize(n+1,0); } int sum(int i){ int s=0; while(i>0){ s+=bit[i]; i-=i&-i; } return s; } void add(int i,int x){ while(i<=n){ bit[i]+=x; i+=i&-i; } } }; signed main(){ int N, Q, T, V, A; cin >> N; BIT bit(N+10); REP(i,N){ cin >> A; bit.add(i+1,A); } cin >> Q; int ans = 0; REP(j,N-24+1){ ans = max(ans, bit.sum(24+j)-bit.sum(j)); } REP(i,Q){ cin >> T >> V; int t = V - (bit.sum(T)-bit.sum(T-1)); bit.add(T,t); if (T <= 24){ REP(j,T+1){ ans = max(ans, bit.sum(24+j)-bit.sum(j)); } }else if (N <= T+24){ REP(j,N-T+1){ ans = max(ans, bit.sum(T+j)-bit.sum(T+j-24)); } }else{ REP(j,24){ ans = max(ans, bit.sum(T+j)-bit.sum(T+j-24)); } } cout << ans << endl; } return 0; }