#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using ll = long long; using P = std::pair; #define rep(i, a, b) for (ll(i) = (a); i < (b); i++) #define all(i) i.begin(), i.end() #define debug(i) std::cout << i << "\n" //const ll MOD = 998244353; const ll MOD = 1e9+7; //とりあえず1-indexedでつくったBIT template struct BinaryIndexedTree { T n; std::vector bit; BinaryIndexedTree(T i) : n(i), bit(i + 1, 0){}; // a番目にwを加算 void add(T a, T w) { for (T x = a; x <= n; x += (x & -x)) { bit[x] += w; } } //[1,a]の和 T sum(T a) { T ret = 0; for (T x = a; x > 0; x -= (x & -x)) { ret += bit[x]; } return ret; } }; int main() { std::cin.tie(0); std::ios::sync_with_stdio(false); //問題文中の添え字が0-indexか1-indexか確認! ll n; std::cin>>n; std::vector a(n),sum(n,0); rep(i,0,n)std::cin>>a[i]; rep(i,0,24)sum[23]+=a[i]; ll max=sum[23]; rep(i,24,n){ sum[i]=sum[i-1]+a[i]-a[i-24]; max=std::max(max,sum[i]); } ll q; std::cin>>q; rep(i,0,q){ ll t,v; std::cin>>t>>v; t--; ll temp=v-a[t]; a[t]=v; rep(j,std::max((ll)23,t),std::min(n,t+24)){ sum[j]+=temp; max=std::max(max,sum[j]); } std::cout<