Problem:


Score : 200 points

Problem Statement

Joisino is about to compete in the final round of a certain programming competition.
In this contest, there are N problems, numbered 1 through N.
Joisino knows that it takes her T_i seconds to solve problem i(1≦i≦N).

Also, there are M kinds of drinks offered to the contestants, numbered 1 through M.
If Joisino takes drink i(1≦i≦M), her brain will be stimulated and the time it takes for her to solve problem P_i will become X_i seconds.
It does not affect the time to solve the other problems.

A contestant is allowed to take exactly one of the drinks before the start of the contest.
For each drink, Joisino wants to know how many seconds it takes her to solve all the problems if she takes that drink.
Here, assume that the time it takes her to solve all the problems is equal to the sum of the time it takes for her to solve individual problems.
Your task is to write a program to calculate it instead of her.

Constraints

All input values are integers.

1≦N≦100

1≦T_i≦10^5

1≦M≦100

1≦P_i≦N

1≦X_i≦10^5

Input

The input is given from Standard Input in the following format:

N
T_1 T_2 ... T_N
M
P_1 X_1
P_2 X_2
:
P_M X_M

Output

For each drink, calculate how many seconds it takes Joisino to solve all the problems if she takes that drink, and print the results, one per line.

Sample Input 1

3
2 1 4
2
1 1
2 3

Sample Output 1

6
9

If Joisino takes drink 1, the time it takes her to solve each problem will be 1, 1 and 4 seconds, respectively, totaling 6 seconds.

If Joisino takes drink 2, the time it takes her to solve each problem will be 2, 3 and 4 seconds, respectively, totaling 9 seconds.

Sample Input 2

5
7 2 3 8 5
3
4 2
1 7
4 13

Sample Output 2

19
25
30



Sample input:
3
2 1 4
2
1 1
2 3


Sample output:
6
9

Submission status: Accepted

Solution code:
N=int(input())
T=list(map(int,input().split()))
M=int(input())
SUM=sum(T)

for _ in range(M):
    i,j=map(int,input().split())
    print(SUM-T[i-1]+j)

Submission status: Accepted

Solution code:
N = int(input())
Problems = list(map(int,input().split()))
M = int(input())
for i in range(M):
    p,t = map(int,input().split())
    k = Problems[p-1]
    Problems[p-1] = t
    print(sum(Problems))
    Problems[p-1] = k

Submission status: Accepted

Solution code:
n=int(input())
t=list(map(int,input().split()))
m=int(input())
p1=[]
x1=[]
for i in range(m):
    p,x=map(int,input().split())
    p1.append(p)
    x1.append(x)
for i in range(m):
    print(sum(t)-t[p1[i]-1]+x1[i])

Submission status: Accepted

Solution code:
n = int(input())
t_list = list(map(int, input().split()))
m = int(input())
for i in range(m):
    tmp_list = list(map(int, input().split()))
    print(sum(t_list) - t_list[tmp_list[0] - 1] + tmp_list[1])

Submission status: Accepted

Solution code:
n = int(input())
t_list = list(map(int, input().split()))
m = int(input())
px_dict = {}
for i in range(m):
    tmp_list = list(map(int, input().split()))
    print(sum(t_list) - t_list[tmp_list[0] - 1] + tmp_list[1])

Submission status: Accepted

Solution code:
N = int(input())
T = list(map(int, input().split()))
M = int(input())
sumT = sum(T)
for _ in range(M):
    p, x = map(int, input().split())
    print(sumT + x - T[p-1])

Submission status: Accepted

Solution code:
N = int(input())
T = list(map(int, input().split()))
for i in range(int(input())):
    p, x = map(int, input().split())
    print(sum(T)-T[p-1]+x)

Submission status: Accepted

Solution code:
n = int(input())
T = list(map(int, input().split()))
sumT = sum(T)
m = int(input())
for i in range(m):
  a, b = map(int, input().split())
  print(sumT - T[a - 1] + b)

Submission status: Accepted

Solution code:
N = int(input())
Ts = [int(x) for x in input().split()]
M = int(input())
for i in range(M):
    p,x = list(map(int,input().split()))
    time = 0
    for j in range(N):
        if j == (p-1):
            time += x
        else:
            time += Ts[j]
    print(time)

Submission status: Accepted

Solution code:
N = int(input())
T = list(map(int, input().split()))
M = int(input())
P = []
X = []
for _ in range(M):
    p, x = map(int, input().split())
    P.append(p)
    X.append(x)

for i in range(0,M):
    T_tmp = T[:]
    T_tmp[P[i]-1] = X[i]
    print(sum(T_tmp))

Submission status: Accepted

Solution code:
int_n = int(input())
li_t = list(map(int, input().split()))
int_m = int(input())
li_p = list()
li_x = list()

for i in range(int_m):
    p, x = map(int, input().split())
    li_p.append(p)
    li_x.append(x)


for x, p in zip(li_p, li_x):
    w_li_t = li_t[:]
    w_li_t[x-1] = p

    print(sum(w_li_t))

Submission status: Accepted

Solution code:
n = int(input())

t = input().split()
sum=0
for i in t:
    sum+=int(i)

m = int(input())
A = []
for j in range(m):
    p, x = map(int, input().split())
    A.append(sum-int(t[p-1]) + x)
for k in A:
    print(k)

Submission status: Accepted

Solution code:
N = int(input())
T = list(map(int, input().split()))
M = int(input())
PX = [tuple(map(int, input().split())) for _ in range(M)]

temp = sum(T)

for i, (p, x) in enumerate(PX):
    ans = temp - T[p - 1] + x
    print(ans)

Submission status: Accepted

Solution code:
N = int(input())
Ts = list(map(int, input().split()))
M = int(input())
PXs = [tuple(map(int, input().split())) for _ in range(M)]

sumT = sum(Ts)
for P, X in PXs:
    print(sumT - Ts[P - 1] + X)

Submission status: Accepted

Solution code:
n=int(input())
t=list(map(int,input().split()))
for i in range(int(input())):
  p,x=map(int,input().split())
  print(sum(t)-t[p-1]+x)

Submission status: Accepted

Solution code:
N = int(input())
T = list(map(int, input().split()))
M = int(input())
P = [0] * M
X = [0] * M
for i in range(M):
    P[i], X[i] = map(int, input().split())

T_original = tuple(T)
for j in range(M):
    T[P[j]-1] = X[j]
    print(sum(T))
    T = list(T_original)

Submission status: Accepted

Solution code:
n=int(input())
t=list(map(int,input().split()))
m=int(input())
s=sum(t)
l=[]
for i in range(m):
  p,x=map(int,input().split())

  l.append(s-t[p-1]+x)
for i in l:
  print(i)

Submission status: Accepted

Solution code:
# 

n=int(input())
t=list(map(int,input().split()))
m=int(input())

for i in range(m):
    p,x=map(int,input().split())
    print(sum(t)-t[p-1]+x)
#コピペです。

Submission status: Accepted

Solution code:
N = int(input())
T = input().rstrip().split(" ")
T = [int(i) for i in T]
M = int(input())
for i in range(M):
    To = T[:]
    temp = input().rstrip().split(" ")
    P = int(temp[0])
    X = int(temp[1])
    T[P-1] = X
    print(sum(T))
    T = To[:]

Submission status: Accepted

Solution code:
n = int(input())
t = list(map(int, input().split()))

m = int(input())

px = []
for i in range(m):
  px.append(list(map(int,input().split())))

for i in px:
  tClone = t[:]
  tClone[i[0] - 1] = i[1]
  print(sum(tClone))

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
m=int(input())
s=sum(a)
for i in range(m):
    p,x=map(int,input().split())
    print(s+x-a[p-1])

Submission status: Accepted

Solution code:
# 

n=int(input())
t=list(map(int,input().split()))
m=int(input())

for i in range(m):
    p,x=map(int,input().split())
    print(sum(t)-t[p-1]+x)

Submission status: Accepted

Solution code:
N = int(input())
T = list(map(int,input().split()))
M = int(input())

d = {}
for i in range(N):
  d[i+1] = T[i]

for i in range(M):
  P, X = map(int,input().split())
  cv = d[P]
  d[P] = X
  print(sum(d.values()))
  d[P] = cv

Submission status: Accepted

Solution code:
N = int(input())
T = list(map(int, input().split()))
M = int(input())
P = [0] * M
X = [0] * M
for i in range(M):
	P[i], X[i] = map(int, input().split())

for i in range(M):
	sum = 0
	for j in range(N):
		if j == (P[i] - 1):
			sum = sum + X[i]
		else:
			sum = sum + T[j]
	print(sum)

Submission status: Accepted

Solution code:
n = int(input())
t = list(map(int,input().split()))
m = int(input())
ans =[]
for i in range(m):
    p,x = map(int,input().split())
    q = sum(t)-t[p-1]+x
    ans.append(q)
for i in range(m):
    print(ans[i])

Submission status: Accepted

Solution code:
def main():
    _ = input()
    ts = list(map(int, input().split()))
    t = sum(ts)
    m = int(input())
    for _ in range(m):
        p, x = map(int, input().split())
        p -= 1
        print(t - ts[p] + x)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
a = input().split()
t = [int(m) for m in a]
m = int(input())
#行列
c = []
for i in range(m):#h:高さ
    c.append([int(m) for m in input().split()])
k = sum(t)
for i in range(m):
    print(k - t[c[i][0] - 1] + c[i][1])

Submission status: Accepted

Solution code:
n = int(input())
t = [int(i) for i in input().split()]

_sum = sum(t)
m = int(input())
for _ in range(m):
    p, x = [int(i) for i in input().split()]
    print(_sum + x - t[p - 1])

Submission status: Accepted

Solution code:
n = int(input())
tlist=list(map(int, input().split()))
m=int(input())
total=sum(tlist)
ans = []
for i in range(m):
    p,x=map(int,input().split())
    ans.append(total-tlist[p-1]+x)

for t in range(m):
    print(ans[t])

Submission status: Accepted

Solution code:
N = int(input())
t_arr = list(map(int, input().split()))
total = sum(t_arr)
M = int(input())
ans_arr = []
for _ in range(M):
    p, x = map(int, input().split())
    ans_arr.append(total - t_arr[p-1] + x)
for m in range(M):
    print(ans_arr[m])

Submission status: Accepted

Solution code:
n = int(input())
t = []
sum = 0

line = input().split(" ")
for i in range(n):
    t.append(int(line[i]))
    sum += int(line[i])

m = int(input())
for i in range(m):
    line = input().split(" ")
    p = int(line[0]) - 1
    x = int(line[1])
    for j in range(len(t)):
        if j == p:
            comp = sum - t[j] + x
    print(comp)

Submission status: Accepted

Solution code:
n = int(input())
t = []
sum = 0
p = []
x = []

line = input().split(" ")
for i in range(n):
    t.append(int(line[i]))
    sum += int(line[i])

m = int(input())
for i in range(m):
    line = input().split(" ")
    p.append(int(line[0]) - 1)
    x.append(int(line[1]))

for i in range(m):
    for j in range(len(t)):
        if j == p[i]:
            comp = sum - t[j] + x[i]
    print(comp)

Submission status: Accepted

Solution code:
N = int(input())
time_list = [int(i) for i in input().split()]
M = int(input())
drinked_time_list = []
for i in range(M) :
    drinked_time_list.append([int(i) for i in input().split()])

base_total_time = sum(time_list)
for dr in drinked_time_list :
    base_time = time_list[dr[0]-1]
    print(base_total_time-base_time+dr[1])

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-


def main():
    """Function."""
    n = int(input())
    t = list(map(int, input().split()))

    base = sum(t)

    m = int(input())
    for _ in range(m):
        num, rep = map(int, input().split())
        num = num - 1
        print(base - t[num] + rep)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
import collections
import itertools
import math
import re
from collections import deque

# MOD = 10 ** 9 + 7

N = int(input())
T = [int(x) for x in input().split()]
M = int(input())
s = sum(T)
for i in range(M):
    p, x = [int(x) for x in input().split()]
    print(s - T[p-1] + x)

Submission status: Accepted

Solution code:
n = int(input())
t = list(map(int, input().split()))
m = int(input())
px = []
for i in range(m):
    px.append(list(map(int, input().split())))
for i in range(m):
    ans = 0
    for j in range(n):
        if px[i][0] == j+1:
            ans += px[i][1]
        else:
            ans += t[j]
    print(ans)

Submission status: Accepted

Solution code:
N = input()
T = map(int, raw_input().split())
M = input()
P = []
X = []
for _ in range(M):
    p, x = map(int, raw_input().split())
    P.append(p)
    X.append(x)
res_normal = sum(T)
for i in range(M):
    print res_normal - T[P[i] - 1] + X[i]

Submission status: Accepted

Solution code:
n=int(input())
T=[0]+list(map(int,input().split()))
m=int(input())
PX=[list(map(int,input().split())) for i in range(m)]


for i,j in PX:
  tmp=T[:i]+[j]+T[i+1:]
  print(sum(tmp))

Submission status: Accepted

Solution code:
N = int(input())
T = list(map(int,input().split()))
M = int(input())
list = [list(map(int,input().split())) for _ in range(M)]
for _ in range(M):
    T_ = [x for x in T]
    T_[list[_][0]-1] = list[_][1]
    num = 0
    for t in T_:
        num += t
    print(num)
#go

Submission status: Accepted

Solution code:
data_num=int(input())
data=input().split()

rdata_num=int(input())
for i in range(rdata_num):
  dict={}
  for i in range(data_num):
    dict[i]=int(data[i])

  list=[]
  p,x=input().split()   
  dict[int(p)-1]=int(x)
  
  for dict_val in dict.values():
    list.append(dict_val)

  print(sum(list))

Submission status: Accepted

Solution code:
N = int(input())
T = [int(_) for _ in input().split()]
M = int(input())
PX = [[int(_) for _ in input().split()] for _ in range(M)]

S = sum(T)
for p, x in PX:
    print(S-T[p-1]+x)

Submission status: Accepted

Solution code:
from copy import deepcopy
n = input()
a = [int(x) for x in input().split()]
m = int(input())
for _ in range(m):
  t = deepcopy(a)
  b,c = [int(x) for x in input().split()]
  t[b-1] = c
  print(sum(t))

Submission status: Accepted

Solution code:
from copy import deepcopy
n = int(input())
a = [int(x) for x in input().split()]
m = int(input())
for _ in range(m):
  t = deepcopy(a)
  b,c = [int(x) for x in input().split()]
  t[b-1] = c
  print(sum(t))

Submission status: Accepted

Solution code:
N=int(input())

a=input().strip().split(" ")
a=[int(j) for j in a]

M=int(input())

for i in range(M):
    c=a[:]
    Sum=0
    b=input().strip().split(" ")
    b=[int(j) for j in b]
    c[b[0]-1]=b[1]
    for k in range(len(c)):
        Sum+=c[k]

    print(Sum)

Submission status: Accepted

Solution code:
n = int(input())
t = list(map(int, input().split()))
m = int(input())
su = sum(t)
for i in range(m):
    p, x = list(map(int, input().split()))
    print(su - t[p-1] + x)

Submission status: Accepted

Solution code:
def abc050_b():
    number_of_problem = int(input())
    time_to_solve_list = [int(i) for i in input().split()]
    sum_of_solve_list = sum(time_to_solve_list)
    
    variety_of_drinks = int(input())

    problem_vs_time = []

    for _ in range(variety_of_drinks):
        buf = list(map(int, input().split()))
        problem_num = buf[0] - 1
        time_to_solve = buf[1]

        problem_vs_time.append([problem_num, time_to_solve])

    for key, value in problem_vs_time:
        print(sum_of_solve_list + value - time_to_solve_list[key])


if __name__ == '__main__':
    abc050_b()

Submission status: Accepted

Solution code:
def abc050_b():
    number_of_problem = int(input())
    time_to_solve_list = [int(i) for i in input().split()]

    variety_of_drinks = int(input())

    problem_vs_time = []

    for _ in range(variety_of_drinks):
        buf = list(map(int, input().split()))
        problem_num = buf[0] - 1
        time_to_solve = buf[1]

        problem_vs_time.append([problem_num, time_to_solve])

    for key, value in problem_vs_time:
        buf = time_to_solve_list[key]
        time_to_solve_list[key] = value

        print(sum(time_to_solve_list))
        time_to_solve_list[key] = buf


if __name__ == '__main__':
    abc050_b()

Submission status: Accepted

Solution code:
N = int(input().rstrip())
T = list(map(int, input().rstrip().split()))
M = int(input().rstrip())

for i in range(M):
    P, X = list(map(int, input().rstrip().split()))
    total = 0
    for j in range(len(T)):
        t = 0
        if j == P - 1:
            t = X
        else:
            t = T[j]

        total += t

    print(total)

Submission status: Accepted

Solution code:
# https://beta.atcoder.jp/contests/abc050/tasks/abc050_b


def solve():
    _ = int(input())
    T = list(map(int, input().split()))
    M = int(input())
    for _ in range(M):
        total = 0
        P, X = map(int, input().split())
        for index, time in enumerate(T):
            if index + 1 == P:
                total += X
            else:
                total += time

        print(total)


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
# coding: utf-8
_ = int(input())
li_T = list(map(int, input().split()))
s_T = sum(li_T)

for _ in range(int(input())):
    p, x = map(int, input().split())
    print(s_T - li_T[p - 1] + x)

Submission status: Accepted

Solution code:
# coding: utf-8
_ = int(input())
li_T = list(map(int, input().split()))

for _ in range(int(input())):
    p, x = map(int, input().split())
    print(sum(li_T) - li_T[p - 1] + x)

Submission status: Accepted

Solution code:
n = int(input())
t = list(map(int,input().split()))
m = int(input())
px = [list(map(int,input().split())) for _ in range(m)]
res = sum(t)
for (p,x) in px:
    print(res + x - t[p-1])

Submission status: Accepted

Solution code:
# coding: utf-8
N = int(input())
li_T = list(map(int, input().split()))
M = int(input())

sum_T = sum(li_T)
for _ in range(M):
    p, x = map(int, input().split())
    i = p - 1
    print(sum_T - li_T[i] + x)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
s = sum (a)
for _ in range(int(input())):
    p,x = map(int,input().split())
    print(s-a[p-1]+x)

Submission status: Accepted

Solution code:
count = int(input())
orline = input()
line = orline.split()
dri = int(input())
sum = 0
for i in range(dri):
  num = input().split()
  line[int(num[0]) - 1] = int(num[1])
  for j in range(count):
    sum += int(line[j])
  print(sum)
  sum = 0
  line[int(num[0]) -1] = orline.split()[int(num[0]) -1]

Submission status: Accepted

Solution code:
# -*- coding: utf-8

n = int(input())
t = list(map(int, input().split()))

for i in range(int(input())):
    p, x = map(int, input().split())
    print(sum(t) - t[p- 1] + x)

Submission status: Accepted

Solution code:
N=int(input())
a=list(map(int,input().split()))
M=int(input())
p=[]
x=[]
for i in range(M):
    p1,x1=[int(i) for i in input().split()]
    p.append(p1)
    x.append(x1)
sum=0
for i in range(N):
    sum+=a[i]
for i in range(M):
    print(sum-a[p[i]-1]+x[i])

Submission status: Accepted

Solution code:
import copy

n=int(input())
t=list(map(int, input().split()))
m=int(input())
px = [list(map(int, input().split())) for _ in range(m)]

for p,x in px:
    ans = copy.copy(t)
    ans[p-1] = x
    print(sum(ans))

Submission status: Accepted

Solution code:
N = int(input().strip())
T = list(map(int, input().strip().split()))
sumT = sum(T)
M = int(input().strip())
for i in range(M):
  P, X = map(int, input().strip().split())
  print(sumT - T[P - 1] + X)

Submission status: Accepted

Solution code:
N = int( input())
T = list( map( int, input().split()))
M = int( input())
PX = [ list( map( int, input().split())) for _ in range(M)]
S = sum(T)
for i in range(M):
    p, x = PX[i]
    print(S - T[p-1] + x)

Submission status: Accepted

Solution code:
N = int(input())
T_l = [int(i) for i in input().split()]
M = int(input())
PX = [[int(i) for i in input().split()] for j in range(M)]

P = [i[0] for i in PX]
X = [i[1] for i in PX]

for i in range(M):
    print(sum(T_l) - T_l[P[i]-1] + X[i])

Submission status: Accepted

Solution code:
n = int(input())
t = list(map(int, input().split()))
m = int(input())

s = sum(t)
for _ in range(m):
  p, x = map(int, input().split())
  print(s + x - t[p - 1])

Submission status: Accepted

Solution code:
N = int(input())
T = list(map(int, input().split()))
M = int(input())

for _ in range(M):
    p, x = map(int, input().split())
    c = T[p-1]
    T[p-1] = x
    print(sum(T))
    T[p-1] = c

Submission status: Accepted

Solution code:
N = int(input())
answer_time = list(map(int, input().split()))
M = int(input())

answer = 0
for _ in range(M):
    p, x = map(int, input().split())
    change = answer_time[p-1]
    answer_time[p-1] = x
    print(sum(answer_time))
    answer_time[p-1] = change

Submission status: Accepted

Solution code:
from copy import deepcopy
n = int(input())
t = list(map(int,input().split()))
m = int(input())
p = []
x = []
for i in range(m):
    tmpp,tmpx = map(int,input().split())
    p.append(tmpp)
    x.append(tmpx)
for j in range(len(p)):
    tmplist = deepcopy(t)
    tmplist[p[j]-1] = x[j]
    print(sum(tmplist))

Submission status: Accepted

Solution code:
n = int(input())
t = list(map(int,input().split()))
sumt = sum(t)
m = int(input())
l = []
for i in range(m):
    p, x = map(int,input().split())
    a = sum(t)+x-t[p-1]
    l.append(a)
for j in l:
    print(j)

Submission status: Accepted

Solution code:
n = int(input())
t = [x for x in map(int, input().split())]
m = int(input())
for _ in range(m):
    p, x = map(int, input().split())
    i = t.copy()
    i[p-1] = x
    print(sum(i))

Submission status: Accepted

Solution code:
n = int(input())
time_li = list(map(int, input().split()))
m = int(input())
drink_li = []
for i in range(m):
    drink_li.append(list(map(int,input().split())))

reg_sum = sum(time_li)

for item in drink_li:
    id = item[0] - 1
    diffrence = item[1] - time_li[id]
    print(reg_sum + diffrence)

Submission status: Accepted

Solution code:
n=int(input())
t=list(map(int,input().split()))
m=int(input())
drink=[]
all=sum(t)
for i in range(m):
  drink.append(list(map(int,input().split())))
for j in range(m):
  if drink[j][0]<=n:
    print(all-t[drink[j][0]-1]+drink[j][1])
  else:
    print(all)

Submission status: Accepted

Solution code:
z = int(input())
ar = list(map(int,input().split(" ")))
y = int(input())
count = 0
for i in range(y):
    l = list(map(int,input().split(" ")))
    for j,a in enumerate(ar):
        if j != l[0] -1:
            count += a
    count += l[1]
    print(count)
    count = 0

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin

sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n = ni()
t = list(li())
total = sum(t)

m = ni()
px = []
for _ in range(m):
    p,x = li()
    p -= 1
    print(total - t[p] + x)

Submission status: Accepted

Solution code:
from sys import stdin


def main():
    n = next_int()
    t = [next_int() for _ in range(n)]

    m = next_int()
    ans = [0] * m

    for i in range(m):
        p = next_int() - 1
        x = next_int()
        ans[i] += sum(t) - t[p] + x

    print("\n".join(map(str, ans)))


def next_int() -> int:
    return int(next_str())


def next_str() -> str:
    result = ""
    while True:
        tmp = stdin.read(1)
        if tmp.strip() != "":
            result += tmp
        elif tmp != '\r':
            break
    return result


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from sys import stdin


def main():
    n = next_int()
    t = [next_int() for _ in range(n)]

    ans = []
    m = next_int()

    for i in range(m):
        p = next_int() - 1
        x = next_int()
        ans += [sum(t) - t[p] + x]

    print("\n".join(map(str, ans)))


def next_int() -> int:
    return int(next_str())


def next_str() -> str:
    result = ""
    while True:
        tmp = stdin.read(1)
        if tmp.strip() != "":
            result += tmp
        elif tmp != '\r':
            break
    return result


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
T = list(map(int, input().split()))
M = int(input())

P_X = []
X = []

for i in range(M):
    p_, x_ = map(int, input().split())
    P_X.append([p_, x_])

for i in range(M):
    p = P_X[i][0] - 1
    x = P_X[i][1]
    if N >= M:
        print(sum(T) -T[p] + x)
    else:
        if p < N :
            print(sum(T) -T[p] + x)
        else :
            print(sum(T))

Submission status: Accepted

Solution code:
#! /usr/bin/python3
# Contest with Drinks Easy

"""
    入力は全て整数である
    1≦N≦100
    1≦Ti≦105
    1≦M≦100
    1≦Pi≦N
    1≦Xi≦105
"""
test = False

N = int(input())
T = list(map(int, input().split()))
M = int(input())
P = []
X = []

for _ in range(M):
    temp_P, temp_X = map(int, input().split())
    P.append(temp_P)
    X.append(temp_X)

if test:
    print('P =', P)
    print('X =', X)


def main():
    """
    飲まないときの時間を基準にして、飲んだ時の差分を引く。
    """
    default_time = sum(T)
    for i in range(M):
        dt = T[P[i] - 1] - X[i] # 速くなる時間
        print(default_time - dt) # かかる時間


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
T = list(map(int,input().split()))
M = int(input())
P = []
X = []
for i in range(M):
    p, x = map(int,input().split())
    P.append(p)
    X.append(x)
T_total = 0

for i in range(N):
    T_total += T[i]

for i in range(M):
    p = P[i] - 1
    ans = T_total - T[p] + X[i]
    print(ans)

Submission status: Accepted

Solution code:
from copy import  deepcopy
N = int(input())
T = list(map(int, input().split()))
M = int(input())

ans = []
for _ in range(M):
    P, X = map(int, input().split())
    t = deepcopy(T)
    t[P-1] = X
    ans.append(sum(t))
    
for a in ans:
    print(a)

Submission status: Accepted

Solution code:
n = int(input())
t = list(map(int,input().split()))
s = sum(t)
m = int(input())
for i in range(m):
    p,x = map(int,input().split())
    print(s - t[p-1] + x)

Submission status: Accepted

Solution code:
n = int(raw_input())
t = map(int, raw_input().split())
s = sum(t)
m = int(raw_input())
for _ in range(m):
    p, x = map(int, raw_input().split())
    print s - t[p - 1] + x

Submission status: Accepted

Solution code:
n = int(raw_input())
t = map(int, raw_input().split())
s = sum(t)
m = int(raw_input())
for _ in range(m):
    p, x = map(int, raw_input().split())
    print s - t[p - 1] + x

Submission status: Accepted

Solution code:
n = int(input())
t = list(map(int, input().split()))
m = int(input())
p = [list(map(int, input().split())) for _ in range(m)]
for i in range(m):
    print(sum(t) - t[p[i][0]-1] + p[i][1])

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# 入力
N = int(input())
T = input().split()
for i in range(0, N):
    T[i] = int(T[i])
M = int(input())
for i in range(0, M):
    p, x = input().split()
    p = int(p)
    x = int(x)
    Time = sum(T) - T[p - 1] + x
    print(Time)

Submission status: Accepted

Solution code:
N = int(input())
T = list(map(int, input().split()))
M = int(input())
ans = []
base = sum(T)

for i in range(M):
    P, X = map(int, input().split())
    ans.append(base-T[P-1]+X)

for i in ans:
    print(i)

Submission status: Accepted

Solution code:
N = int(input())
T = list(map(int, input().split()))
M = int(input())
P, X, ans = [0]*M, [0]*M, []
base = sum(T)

for i in range(M):
    P, X = map(int, input().split())
    ans.append(base-T[P-1]+X)

for i in ans:
    print(i)

Submission status: Accepted

Solution code:
N=int(input())
T=list(map(int,input().split()))
M=int(input())
PX=[list(map(int,input().split())) for i in range(M)]
import copy
for i in range(len(PX)):
    TC=copy.deepcopy(T)
    TC[PX[i][0]-1]=PX[i][1]
    print(sum(TC))

Submission status: Accepted

Solution code:
n = int(input())
listT = list(map(int, input().split()))
sumT =0
index3 =0
while index3 < len(listT):
    sumT+=listT[index3]
    index3+=1
m = int(input())
listForL = []
index=0
while index < m:
    pXList = list(map(int, input().split()))
    listForL.append(pXList)
    index+=1

listForA = []
index2 =0
while index2 < len(listForL):
    sum = sumT - listT[listForL[index2][0]-1] + listForL[index2][1]
    listForA.append(sum)
    index2+=1

for ans in listForA:
    print(ans)

Submission status: Accepted

Solution code:
n = int(input())
t = [0] + list(map(int,input().split()))
s = sum(t)
for _ in [0]*int(input()):
  p,x = map(int,input().split())
  print(s-t[p]+x)

Submission status: Accepted

Solution code:
N = int(input())
L = list(map(int,input().split()))
m = int(input())
P = [list(map(int,input().split())) for i in range(m)]
S = sum(L)
for i in range(m):
  print(S-L[P[i][0]-1]+P[i][1])

Submission status: Accepted

Solution code:
N = int(input())
T = [int(_) for _ in input().split()]
M = int(input())
Total = sum(T)
output = []
for i in range(M):
    p, x = map(int, input().split())
    output.append(Total - (T[p-1] - x))
for i in range(M):
    print(output[i])

Submission status: Accepted

Solution code:
n = int(input())
list_t = list((map(int, input().split())))
m = int(input())
count = 0
list_px = []
while count < m:
    list_px.append(list(map(int, input().split())))
    count += 1
list_t_sum = 0
for number in list_t:
    list_t_sum += number
for i in range(0,m):
    print(list_t_sum - list_t[list_px[i][0]-1] + list_px[i][1])

Submission status: Accepted

Solution code:
n = int(input())
t = [int(i) for i in input().split()]
m = int(input())

total = sum(t)
for i in range(m):
    p, x = [int(i) for i in input().split()]
    print(total - (t[p - 1] - x))

Submission status: Accepted

Solution code:
N=int(input())
T=list(map(int,input().split(" ")))
M=int(input())
drink=[list(map(int,input().split(" "))) for _ in range(M)]
def_sum=sum(T)

for i in range(M):
  print(def_sum-(T[drink[i][0]-1]-drink[i][1]))

Submission status: Accepted

Solution code:
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def main():
    N = int(input())
    T = list(map(int, input().split()))
    total = sum(T)
    M = int(input())
    for _ in range(M):
        P, X = map(int, input().split())
        P -= 1
        print(total - T[P] + X)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n=int(input())
t=list(map(int,input().split()))
s=sum(t)
m=int(input())
for _ in range(m):
  i,u=map(int,input().split())
  print(s-t[i-1]+u)

Submission status: Accepted

Solution code:
N = int(input())
T = list(map(int, input().split()))
M = int(input())
for i in range(M):
    P, X = map(int, input().split())
    result = sum(T[:P-1]) + X + sum(T[P:])
    print(result)

Submission status: Accepted

Solution code:
n = int(input())

t = list(map(int, input().split()))

#print("0_OK")

m = int(input())

#print("1_OK")

ans = []

for i in range(m):
    p, x = map(int, input().split())
    tsum = sum(t)
    tsum = tsum - t[p - 1] + x
    ans.append(tsum)

for i in ans:
    print(i)

Submission status: Accepted

Solution code:
n=int(input())
t=list(map(int,input().split()))
m=int(input())
ans=[]
for i in range(m):
    p,x=map(int,input().split())
    tot=sum(t)
    tot=tot-t[p-1]+x
    ans.append(tot)
for i in ans:
    print(i)

Submission status: Accepted

Solution code:
N = int(input())
T = list(map(int,input().split()))
M = int(input())
for i in range(M) :
    p,x = map(int,input().split())
    q = T[p-1]
    T[p-1] = x
    print(sum(T))
    T[p-1] = q

Submission status: Accepted

Solution code:
N = int(input())
T = list(map(int, input().split()))
M = int(input())
for i in range(M):
    p,x = map(int, input().split())
    ans = sum(T[:p-1]) + x + sum(T[p:])

    print(ans)