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:
import sys
input=sys.stdin.readline

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

s = sum(T)
for i in range(M):
    p,x = map(int, 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_x = []
for i in range(m):
    p_x.append(list(map(int, input().split())))
for i in range(m):
    t_sub = t.copy()
    t_sub[p_x[i][0]-1] = p_x[i][1]
    print(sum(t_sub))

Submission status: Accepted

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

Submission status: Accepted

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


m = int(input())
drink = []

for i in range(m):
  drink.append(list(map(int, input().split())))
  
total = sum(times)

for i in range(m):
    print(total- times[drink[i][0]-1] + drink[i][1])

Submission status: Accepted

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

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

Submission status: Accepted

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

PX = []

for _ in range(M):
    p, x = map(int, input().split())
    PX.append((p, x))

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

Submission status: Accepted

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

original_sum = sum(Ts)

for p, x in PX_list:
  print(original_sum - Ts[p-1] + x)

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)
for i in range(M):
    print(sum(T)-T[P[i]-1]+X[i])

Submission status: Accepted

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

for i in range(0,M):
  x,y = map(int,input().split(' '))
  print(SUM -T[x-1] + y)

Submission status: Accepted

Solution code:
#!/usr/bin/env python
num_of_pro = raw_input()
problems = raw_input()
num_of_drinks = raw_input()
drinks_lines = []
count = 0 
while count < int(num_of_drinks):
	count += 1
	each_line = raw_input()
	drinks_lines.append(each_line)
for each_line in drinks_lines:
	problem_num = [int(each_num) for each_num in problems.split()]
	problem_num[int(each_line.split()[0]) -1] = int(each_line.split()[1])
	print sum(problem_num)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
p_list = list(map(int,input().split()))
ans_list=[]
M = int(input())
for _ in range(M):
  ite,mount=map(int,input().split())
  temp_p = p_list.copy()
  temp_p[ite-1]=mount
  print(sum(temp_p))

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)]

t_sum = sum(t)

for i in range(m):
    print(t_sum-t[px[i][0]-1]+px[i][1])

Submission status: Accepted

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

for i in range(M):
  drink=list(map(int,input().split()))
  result=sum(li)-li[drink[0]-1]+drink[1]
  print(result)

Submission status: Accepted

Solution code:
N=int(input())
T=[int(x) for x in input().split()]
M=int(input())
P=[]
X=[]
for i in range(M):
    p1,x1=(int(d) for d in input().split())
    P.append(p1)
    X.append(x1)
sum1=0
for i in range(N):
    sum1+=T[i]
for i in range(M):
    temp=sum1
    temp=temp-T[P[i]-1]+X[i]
    print(temp)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
t = list(map(int, input().split()))
m = int(input())
a = [list(map(int, input().split())) for i in range(m)]
for i, j in a:
    tt = t.copy()
    tt[i-1] = j
    print(sum(tt))

Submission status: Accepted

Solution code:
n =int(input())

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

m = int(input())

p = []

p = [[int(i) for i in input().split()] for _ in range(m)]

for ii in range(m):
    if p[ii][0] <= n:
        total_time = sum(t) - t[p[ii][0]-1] + p[ii][1]
    else:
        total_time = sum(t)
    
    print(total_time)

Submission status: Accepted

Solution code:
n = int(input())

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

m = int(input())

p=[]
x=[]
for _ in range(m):
    pp, xx= map(int, input().split())
    p.append(pp)
    x.append(xx)

for i in range(m):
    count=x[i]
    for j in range(n):
        if j==p[i]-1:
            pass
        else:
            count+=t[j]
    print(count)

Submission status: Accepted

Solution code:
# ABC050b
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

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:
n = int(input())
t = list(map(int,input().split()))
sun = sum(t)
m = int(input())
for i in range(m):
  a,b = map(int,input().split())
  print( sun - t[a-1] + b )

Submission status: Accepted

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

Submission status: Accepted

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

M = int(input())

for m in range(0, M):
    P, X = map(int, input().split())
    print(sum(TList) - TList[P - 1] + X)

Submission status: Accepted

Solution code:
num = int(input())
time = list(map(int, input().split()))
drink = int(input())
eff = [list(map(int, input().split())) for i in range(drink)]

baseT = sum(time)
for i in range(drink):
    print(baseT - time[eff[i][0]-1] + eff[i][1])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
n=int(input())
tt=list(map(int,input().split()))
s=sum(tt)
m=int(input())
for _ in range(m):
    p,x=map(int,input().split())
    print(s-tt[p-1]+x)

Submission status: Accepted

Solution code:
import copy
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):
    T_copy = copy.copy(T)
    drink_number = P[i]
    T_copy[drink_number - 1] = X[i]
    print(sum(T_copy))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(m):
    print(s - t[p[i]-1] + x[i])

Submission status: Accepted

Solution code:
N = int(input())

T = [int(x) for x in input().split()]
sumT = sum(T)

M = int(input())
for _ in range(M):
	P, X = [int(x) for x in input().split()]
	print(sumT + X - T[P - 1])

Submission status: Accepted

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

time=sum(T)

for i in range(m):
    p,x=map(int,input().split())
    print(time-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):
  ans = s - t[PX[i][0]-1] + PX[i][1]   
  print(ans)

Submission status: Accepted

Solution code:
n = int(input())

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

p = []
x = []
for _ in range(m):
    pi, xi = map(int, input().split())
    p.append(pi)
    x.append(xi)

for i in range(m):
    pi = p[i]
    xi = x[i]
    ans = 0
    for j in range(n):
        if j + 1 == pi:
            ans += xi
        else:
            ans += t[j]
    print(ans)

Submission status: Accepted

Solution code:
N = int(input())
tList = list(map(int, input().split()))
M = int(input())
pLst = [list(map(int, input().split())) for i in range(M)]
ansLst = [0] * M

for i in range(M):
    tmp = 0
    for j in range(N):
        if j == (pLst[i][0] - 1):
            tmp += pLst[i][1]
        else:
            tmp += tList[j]

    ansLst[i] = tmp

for i in ansLst:
    print(i)

Submission status: Accepted

Solution code:
N = int(input())
T = [int(x) for x in input().split()]
total = sum(T)
M = int(input())
D = [None]*M
for i in range(M):
  D[i] = [int(x) for x in input().split()]
  D[i][0]-=1
  
for p, x in D:
  print(total - (T[p] - x))

Submission status: Accepted

Solution code:
n=int(input());*t,=map(int,input().split())
s=sum(t)
for i in[0]*int(input()):
	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())
P = [0] * M
X = [0] * M
for i in range(M):
  P[i] , X[i] = map(int, input().split())
sum_T = sum(T)
for i in range(M):
  print(sum_T-T[P[i]-1]+X[i])

Submission status: Accepted

Solution code:
N = int(input())
times = list(map(int, input().split()))
M = int(input())
sum_t = sum(times)
for _ in range(M):
  dist, time = map(int, input().split())
  if times[dist-1] >= time:
    print(sum_t-(times[dist-1]-time))
  else:
    print(sum_t+(time-times[dist-1]))

Submission status: Accepted

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

for i in range(m):
  time = 0
  for j in range(n):
    if j == p[i][0]-1:
      time += p[i][1]
    else:
      time += t[j]
    
  print(time)

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())
arr = [list(map(int,input().split())) for _ in range(m)]
for i in range(len(arr)):
  sums = 0
  sums += sum(t) - t[arr[i][0]-1] + arr[i][1]
  print(sums)

Submission status: Accepted

Solution code:
# ABC 50 B - contest with drink easy
n = int(input())
T = [int(el) for el in input().split(' ')]
m = int(input())
total_T = sum(T)
d = {}
for i in range(m):
    p, x = [int(el) for el in input().split(' ')]
    print(total_T - (T[p-1] - x))

Submission status: Accepted

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

M = int(input())
P, X = [], []
for i in range(M):
    p, x = map(int, input().rstrip().split())
    P.append(p)
    X.append(x)

A = sum(T)

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

Submission status: Accepted

Solution code:
n=int(input())
timelist=[int(i) for i in input().split()]
drinknum=int(input())
for i in range(drinknum):
    timelist2=timelist[:]
    qnum,time=[int(i) for i in input().split()]
    timelist2[qnum-1]=time
    sumtime=0
    for t in timelist2:
        sumtime+=t
    print(sumtime)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys, math, fractions, itertools


def solve(N: int, T: "List[int]", M: int, P: "List[int]", X: "List[int]"):
    sm = sum(T)
    for i in range(M):
        p = P[i]
        x = X[i]
        print(sm - T[p-1] + x)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    T = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    M = int(next(tokens))  # type: int
    P = [int()] * (M)  # type: "List[int]" 
    X = [int()] * (M)  # type: "List[int]" 
    for i in range(M):
        P[i] = int(next(tokens))
        X[i] = int(next(tokens))
    solve(N, T, M, P, X)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import  numpy   as np
import  copy   
i_N =   int(input())
i_T =   input().split()
i_T =   np.array(i_T).astype(type(i_N))
i_M =   int(input())
i_X =   []
for i in range(i_M):
    i_tmp   =   input().split()
    i_X.append(i_tmp)

for P,X in i_X:
    i_calc  =   copy.deepcopy(i_T)
    i_calc[int(P)-1]  =   int(X)
    print(np.sum(i_calc))

Submission status: Accepted

Solution code:
import copy
N=int(input())
Tn=[int(x) for x in input().split()]
M=int(input())
for _ in range(M):
  P,X=[int(x) for x in input().split()]
  tTn=copy.deepcopy(Tn)
  tTn[P-1]=X
  print(sum(tTn))

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())
    print(sum(T) - T[P[i]-1] + X[i])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
t=input().split()
#n==len(t)
m=int(input())
px=[]
for i in range(m):
  px.append(input().split())
res=0
for j in range(1,m+1):
  for k in range(1,n+1):	
    if k==int(px[j-1][0]):
      res+=int(px[j-1][1])
      #print(12345)
    else:
      res+=int(t[k-1])
      #print('drink')
  print(res)
  res=0

Submission status: Accepted

Solution code:

from collections import Counter
import sys

def main():

    num = int(input())
    data = list(map(int, input().split()))
    num_d = int(input())
    cheet_data = [list(map(int, input().split())) for i in range(num_d)]

    sum_data = sum(data)

    for i in range(num_d):
        a, b, = cheet_data[i]
        ans = sum_data - data[a - 1] + b
        print(ans)




if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
t0 = list(map(int, input().split()))
m = int(input())
px = []
while True:
    try:
        px.append(list(map(int, input().split())))
    except:
        break;
import copy

for i in range(m):
    #shallow copy , deep copy の話
    t = []
    t = copy.copy(t0)
    t[px[i][0]-1] = px[i][1]
    print(sum(t))

Submission status: Accepted

Solution code:
n = int(input())
t = list(map(int, input().split()))
total = sum(t)
m = int(input())
for i in range(m):
    p, x = map(int, 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())
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())
for _ 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()))
time = sum(t)
m = int(input())
for i in range(m):
  p, x = map(int, input().split())
  print(time+x-t[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 = list(map(int,input().split()))
  Z = T[:]
  Z[P-1] = X
  print(sum(Z))

Submission status: Accepted

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

Submission status: Accepted

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

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

M = int(input())

for i in range(M):
    p,x = map(int,input().split())
    
    sub = - T[p-1] + x
    print(total+sub)

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())
    sum = 0
    for j in range(p - 1):
        sum = sum + T[j]
    sum = sum + x
    for j in range(p , N):
        sum = sum + T[j]
    print(sum)

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):
    print(s - T[px[i][0] - 1] + px[i][1])

Submission status: Accepted

Solution code:
##input##
Nvar = int(input())
T_list = list(map(lambda x:int(x),input().split(" ")))
M_var = int(input())
P_list = []
for i in range(M_var):
    P_list.append(list(map(lambda x:int(x),input().split(" "))))
##

for d_num in range(M_var):
    time_sum = 0
    for q_num in range(Nvar):
        if q_num==P_list[d_num][0]-1:
            time_sum += P_list[d_num][1]
        else:
            time_sum += T_list[q_num]
    print(time_sum)

Submission status: Accepted

Solution code:
a = int(input())
b = list(map(int, input().split()))

c = int(input())
d = [list(map(int, input().split())) for _ in range(c)]

e = sum(b)
for i in range(c):
    print(e - b[d[i][0]-1] + d[i][1])

Submission status: Accepted

Solution code:
n = int(input())
t  = list(map(int, input().split()))
m = int(input())
problem = []
for _ in range(m):
  hoge = list(map(int, input().split()))
  problem.append(hoge)
for i, fuga in enumerate(problem):
  drink_p, drink_p_time= fuga
  res = 0
  for p, p_time in enumerate(t):
    if(p == drink_p-1):
      res += drink_p_time
    else:
      res += p_time
  print(res)

Submission status: Accepted

Solution code:
N = int(input())
Problems = list(map(int, input().split()))
M = int(input())
arr = []
for i in range(M):
  P, T = map(int, input().split())
  sum = 0
  for j in range(N):
    if j != P - 1:
      sum += Problems[j]
    else:
      sum += T
  arr.append(sum)
for num in arr:
  print(num)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(300000)


def solve(N: int, T: "List[int]", M: int, P: "List[int]", X: "List[int]"):
    for j in range(M):
        ret = 0
        for i in range(N):
            if i == P[j] - 1:
                ret += X[j]
            else:
                ret += T[i]
        print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    T = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    M = int(next(tokens))  # type: int
    P = [int()] * (M)  # type: "List[int]" 
    X = [int()] * (M)  # type: "List[int]" 
    for i in range(M):
        P[i] = int(next(tokens))
        X[i] = int(next(tokens))
    solve(N, T, M, P, X)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    a = ["a", "i", "u", "e", "o"]
    c = S()
    if c[0] in a:
        print("vowel")
    else:
        print("consonant")
    return

#B
def B():
    _ = II()
    t = LI()
    tsum = sum(t)
    for _ in range(II()):
        p, x = LI()
        print(tsum - t[p - 1] + x)
    return

#C
def C():
    return

#D
def D():
    return

#Solve
if __name__ == '__main__':
    B()

Submission status: Accepted

Solution code:
N = int(input())
Ts = [int(i) for i in input().split()]

drinks = []
for i in range(int(input())):
    drinks.append([int(i) for i in input().split()])

for i, j in drinks:
    cp = list(Ts)
    cp[i - 1] = j
    print(sum(cp))

Submission status: Accepted

Solution code:
n = int(input())
time_list = list(map(int,input().split()))
m = int(input())
drink_list = [list(map(int,input().split())) for _ in range(m)]
sum_time = sum(time_list)

for d in drink_list:
    effect_index = d[0] - 1
    effect_time = d[1]
    print(sum_time - time_list[effect_index] + effect_time)

Submission status: Accepted

Solution code:
N=int(input())
T=[int(x) for x in input().split()]
M=int(input())
for _ 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())
PX = [list(map(int,input().split())) for _ in range(M)]

S = sum(T)
for i in range(M):
    print(S - T[PX[i][0]-1] + PX[i][1])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

for e in res:
    print(e)

Submission status: Accepted

Solution code:
n=int(input())
q=input().split()
sum=0
for i in range(n):
    sum+=int(q[i])
#print(sum) 
d=int(input())
for j in range(d):
    a,t=map(int,input().split())
    print(sum-int(q[a-1])+t)

Submission status: Accepted

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

for i in range(m):
    ans = time_li.copy()
    s,t = map(int,input().split())
    ans[s-1] = t
    print(sum(ans))

Submission status: Accepted

Solution code:
a = int(input())
b = list(map(int, input().split()))
c = int(input())
for i in range(c):
    d, e = map(int, input().split())
    print(sum(b) - b[d-1] + e)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter
from collections import deque
from functools import reduce
from operator import mul
from pprint import pprint
import bisect
import copy
import fractions
import itertools
import math
import queue
import random
import sys
import time
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def MI(): return map(int, sys.stdin.readline().split())
def II(): return int(sys.stdin.readline())
def IS(): return input()
def C(x): return Counter(x)
def GCD_LIST(numbers): return reduce(fractions.gcd, numbers)
def LCM_LIST(numbers): return reduce(LCM, numbers)
def LCM(m, n): return (m * n // fractions.gcd(m, n))
def COMBINATION(n, r):
    if n < 0 or r < 0 or n < r:
        return 0
    r = min(n-r, r)
    if r == 0:
        return 1
    o = reduce(mul, range(n, n - r, -1))
    u = reduce(mul, range(1, r + 1))
    return o // u
class UnionFind():

    def __init__(self, n):
        self.n = n
        self.node = [i for i in range(n)]
        self.size = [1 for _ in range(n)]

    def same(self, x, y):
        return bool(self.root(x) == self.root(y))

    def root(self, x):
        if self.node[x] == x:
            return x
        else:
            self.node[x] = self.root(self.node[x])  # 経路圧縮
            return self.node[x]

    def unite(self, x, y):
        x, y = self.root(x), self.root(y)
        if x == y:
            return  # 結合不要
        if self.size[x] < self.size[y]:
            x, y = y, x
        self.node[y] = x
        self.size[x] += self.size[y]

    def return_size(self, x):
        return self.size[self.root(x)]


n = II()
t = LI()
m = II()
drink = [LI() for _ in range(m)]
tsum = sum(t)
for p, x in drink:
    print(tsum - t[p-1] + x)

Submission status: Accepted

Solution code:
import sys
n=int(input())
lineas=sys.stdin.readline()
arr=[]
arr=lineas.split()
arr=list(map(int,arr))
arr.insert(0,0)
m=int(input())
suma=0
lineas2=sys.stdin.readlines()
for i in range(m):
  arr2=lineas2[i].split()
  p=int(arr2[0])
  x=int(arr2[1])
  arr3=arr[:]
  arr3[p]=x
  for i in arr3:
    suma=suma+i
  print(suma)
  suma=0

Submission status: Accepted

Solution code:
N = int(input())
T = list(map(int, input().split()))
M = int(input())
D = []
for i in range(M):
    a, b = input().split()
    D.append((int(a), int(b)))

time = sum(T)

for k in range(M):
    print(time - T[D[k][0]-1] + D[k][1])

Submission status: Accepted

Solution code:

N = int(input())

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

M = int(input())

summ = sum(T)

for i in range(M):

    P,X = map(int,input().split())

    ans = summ - T[P - 1] + X
    print (ans)

Submission status: Accepted

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

for i in range(m):
    print(ans_l[i])

Submission status: Accepted

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

for _ 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()))
s = sum(t)
m = int(input())

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

for i in res:
    print(i)

Submission status: Accepted

Solution code:
n = int(input())
l = list(map(int, input().split(" ")))
s = sum(l)
num = int(input())
for x in range(num):
    a = list(map(int, input().split()))
    ans = s + a[1] - l[a[0]-1]
    print(ans)

Submission status: Accepted

Solution code:
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())
    tmpp -= 1
    p.append(tmpp)
    x.append(tmpx)
    
_sum = sum(t)

for i in range(m):
    print(_sum - (t[p[i]]-x[i]))

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    t = list(map(int,input().split(' ')))
    m = int(input())
    d = []
    for i in range(m):
        d.append(list(map(int,input().split(' '))))
    s = sum(t)
    for i,j in d:
        print(s-t[i-1]+j)
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
T = [int(t) for t in input().split()]
M = int(input())
P, X = [], []
for m in range(M):
    line = input().split()
    P.append(int(line[0]))
    X.append(int(line[1]))

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

Submission status: Accepted

Solution code:
n = int(input())
t = list(map(int, input().split()))
Sum = sum(t)
m = int(input())
for i in range(m):
    p, x = map(int, input().split())
    print(Sum - 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())

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