from itertools import accumulate import sys input = sys.stdin.buffer.readline sys.setrecursionlimit(10 ** 7) N = int(input()) A = list(map(int, input().split())) Q = int(input()) query = tuple(tuple(map(int, input().split())) for _ in range(Q)) B = [0] + list(accumulate(A)) B = [r - l for l, r in zip(B, B[24:])] ans = max(B) for t, v in query: up = v - A[t - 1] A[t - 1] = v L = max(0, t - 24) R = min(len(B), t) for i in range(L, R): B[i] += up ans = max(ans, B[i]) print(ans)