#include #include #include using namespace std; int n,t[400010] = {},mx = 0; void built(){ for(int i = n-1;i>0;i--){ t[i] = t[i<<1] + t[i<<1|1]; } } void update(int p,int a){ for(t[p+=n] = a;p>1;p >>= 1){ t[p>>1] = t[p] + t[p^1]; } } int query(int l, int r){ int mn = mx; for(l += n, r += n; l>= 1,r >>= 1){ if(l&1) mn += t[l++]; if(r&1) mn += t[--r]; } return mn; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int i,j,q; cin >> n; for(i=0;i> a; t[i + n] = a; } built(); int mx = -1; for(i=0;i<=n - 24;i++){ mx = max(mx,query(i,i + 24)); } cin >> q; for(i=0;i> t >> v; t--; update(t,v); for(j=t - 24;j<=t;j++){ if(j<0) continue; if(j + 24>n) continue; mx = max(mx,query(j,j + 24)); } cout << mx << endl; } }