#include using namespace std; #define int long long #define FOR(i, s, n) for (int i = (s); i < (n); i++) #define RFOR(i, s, n) for (int i = (n) - 1; i >= (s); i--) #define REP(i, n) FOR(i, 0, n) #define RREP(i, n) RFOR(i, 0, n) #define ALL(a) a.begin(), a.end() const long long MOD = 1e9+7, INF = 1e18; templateinline bool CHMAX(T&a,T b){if(ainline bool CHMIN(T&a,T b){if(a>b){a=b;return true;}return false;} template class SegmentTree{ private: int N; T initVal; std::vectorary; std::functionmerge; void init(int n){ while(N < n)N <<= 1; ary.resize(N << 1,initVal); } public: SegmentTree(int n,T initVal,std::functionf): N(1),initVal(initVal),merge(f){init(n);} // -- a[i] = val; inline void update(int i,T val){ ary[i += N] = val; while(i > 1){ i >>= 1; ary[i] = merge(ary[i << 1],ary[(i << 1) + 1]); } } // -- a[i] += val; inline void add(int i,T val){ update(i,ary[i + N] + val); } // -- [l,r) inline T query(int l,int r){ if(l >= r)return initVal; T vr = initVal,vl = initVal; for(l += N,r += N;l != r;l >>= 1,r >>= 1){ if(l & 1)vl = merge(vl,ary[l++]); if(r & 1)vr = merge(vr,ary[--r]); } return merge(vl,vr); } /* void debug show(){ for(iint i = N;i < N;i++)std::cerr << ary[i] << ' '; std:::cerr << '\n'; } */ }; using ST = SegmentTree; #define SUM ST(n,0,[](int &a,int &b){return a+b};); #define MIN ST(n,INF,[](int &a,int &b){return min(a,b);}); #define MAX ST(N,0,[](int &a,int &b){return max(a,b);}); //REP(i,N)f(seg.query(0,i),seg.query(i+1,N))でiを除いた全探索 signed main(){ int N; cin>>N; vectora(N); REP(i,N)cin>>a[i]; auto seg = ST(N,0,[](int &a,int &b){return max(a,b);}); REP(i,N){ REP(j,24){ int l = i - j; if(l>=0)seg.add(l,a[i]); } } int Q; cin>>Q; vectorans(Q,0); REP(i,Q){ int t,x; cin>>t>>x; t--; REP(j,24){ int l = t - j; if(l>=0)seg.add(l,x-a[t]); } a[t] = x; ans[i] = seg.query(0,N-23); } for(auto e:ans){ cout<