class Fenwick_Tree: def __init__(self, n): self.n = n self.data = [0] * n def add(self, p, x): p += 1 while p <= self.n: self.data[p - 1] += x p += p & -p def sum(self, l, r): '''範囲[l, r)(lからr-1まで)の総和を求める''' return self._sum(r) - self._sum(l) def _sum(self, r): '''範囲[0, r)(0からr-1まで)の総和を求める''' s = 0 while r > 0: s += self.data[r - 1] r -= r & -r return s n = int(input()) A = list(map(int, input().split())) FT = Fenwick_Tree(n) for i in range(n): FT.add(i, A[i]) res = 0 for i in range(n - 23): res = max(res, FT.sum(i, i + 24)) q = int(input()) for _ in range(q): t, v = map(int, input().split()) t -= 1 pv = FT.sum(t, t + 1) FT.add(t, v - pv) for i in range(t + 1, min(n, t + 24) + 1): res = max(res, FT.sum(max(0, i - 24), i)) print(res)