n = int(input()) a = [int(i) for i in input().split()] q = int(input()) tv = [[int(i) for i in input().split()] for j in range(q)] class Bit: def __init__(self, n): self.size = n self.tree = [0] * (n + 1) def sum(self, i): s = 0 while i > 0: s += self.tree[i] i -= i & -i return s def add(self, i, x): while i <= self.size: self.tree[i] += x i += i & -i ki = Bit(n+1) for i in range(n): ki.add(i+1,a[i]) ans = 0 for i in range(n-24): tmp = ki.sum(i+1+24)-ki.sum(i+1) ans = max(ans,tmp) for i in range(q): t,v = tv[i] ki.add(t,v - (ki.sum(t)-ki.sum(t-1))) for j in range(24): if t-24+j < 0: continue if t+j > n+1: continue tmp = ki.sum(t+j)-ki.sum(t-24+j) ans = max(ans,tmp) print(ans)