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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def solve() : 
  time = list()
  
  N = int(input())
  
  time = list(map(int, input().split()))
  
  M = int(input())
  
  for i in range(M) : 
    p, x = tuple(map(int, input().split()))
    
    ans = time.copy()
    ans[p - 1] = x
    sum = 0
    for j in range(len(ans)) :
      sum += ans[j]
    print(sum)
    
solve()

Submission status: Accepted

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

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)]
k = 0
tmp = t[:]
for i in range(m):
    k = p[i][0]
    t[k-1] = p[i][1]
    print(sum(t))
    t[k-1] = tmp[k-1]

Submission status: Accepted

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

total_time = sum(T)
for i in range(M):
    p, x = PX[i]
    print(total_time - T[p - 1] + x)

Submission status: Accepted

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

t = sum(T)

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

Submission status: Accepted

Solution code:
import copy
n = int(input())
t = list(map(int, input().split()))
m = int(input())
d = []
ans = []
for i in range(m):
    d.append(list(map(int, input().split())))
for i in range(m):
    s = copy.copy(t)
    s[d[i][0] - 1] = d[i][1]
    ans.append(sum(s))
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 = list(map(int,input().split()))
    a = t.copy()
    a[p-1] = x
    print(sum(a))

Submission status: Accepted

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

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

Submission status: Accepted

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

total = sum(T)

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

Submission status: Accepted

Solution code:
"""
N = list(map(int,input().split()))
S = [str(input()) for _ in range(N)]
S = [list(map(int,list(input()))) for _ in range(h)] 
print(*S,sep="")
"""

import sys
sys.setrecursionlimit(10**6)
input = lambda: sys.stdin.readline().rstrip()
inf = float("inf") # 無限

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

Submission status: Accepted

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

Submission status: Accepted

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

S = sum(T)

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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())
  sumi=sum-t[p-1]+x
  print(sumi)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
t = list(map(int, input().split()))
m = int(input())
px = {}
for i in range(m):
  p, x = map(int, input().split())
  px[i] = [p, x]
time = [sum(t)] * m
for i in range(len(px)):
  time[i] = time[i] - t[px[i][0] - 1] + px[i][1]
for e in time:
  print(e)

Submission status: Accepted

Solution code:
n=int(input())
t=list(map(int,input().split()))
m=int(input())
t_tot=sum(t)
p=x=0
a=0

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import math
def I():return int(sys.stdin.readline().replace("\n",""))
def I2():return map(int,sys.stdin.readline().replace("\n","").split())
def S():return str(sys.stdin.readline().replace("\n",""))
def L():return list(sys.stdin.readline().replace("\n",""))
def Intl():return [int(k) for k in sys.stdin.readline().replace("\n","").split()]
def Lx(k):return list(map(lambda x:int(x)*-k,sys.stdin.readline().replace("\n","").split()))

n = I()
t = Intl()
m = I()
px = [Intl() for i in range(m)]
#print(px)
s = sum(t)
time = s
for i in range(m):
    print(time-t[px[i][0]-1]+px[i][1])
    time = s

Submission status: Accepted

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

drink = list()

for a in range(m):
    drink.append(list(map(int, input().split())))

x = 0

for a in range(m):
    for b in range(n):
        if drink[a][0] == b+1:
            x += drink[a][1]
        else:
            x += init_time[b]
    print(x)
    x = 0

Submission status: Accepted

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

Submission status: Accepted

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

def calc(lis):
	T2 = T.copy()
	T2[lis[0]-1] = lis[1]
	return sum(T2)

for i in range(M):
	print(calc(P[i]))

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.buffer.readline
N = int(input())
T = [0] + list(map(int, input().split()))
sum_T = sum(T)
M = int(input())
# print('sum_T', sum_T)
for _ in range(M):
    p, x = map(int, input().split())
    # print('p, x', p, x)
    t = sum_T - T[p] + x
    print(t)

Submission status: Accepted

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

total = sum(t)
for _ 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[:P-1])+X+sum(T[P:]),end="\n")

Submission status: Accepted

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

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:
prob = int(input())
sec = [int(n)for n in input().split()]
su = sum(sec)
for _ in range(int(input())):
    p, x = map(int, input().split())
    print(su - sec[p - 1] + x)

Submission status: Accepted

Solution code:
n = int(input())
t = [int(i) for i in input().split()]
s = sum(t)
m = int(input())
ans = []
for _ in range(m):
    p,x = map(int,input().split())
    p -= 1
    ans.append(s-t[p]+x)
print("\n".join(map(str,ans)))

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())
  diff = T[P-1]-X
  print(S-diff)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from copy import deepcopy

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(M):
    ans = deepcopy(T)
    ans[P[i] - 1] = X[i]
    print(sum(ans))

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

for p, x in px:
    ans = 0
    for i in range(n):
        if i == p - 1:
            ans += x
        else:
            ans += t[i]
    print(ans)

Submission status: Accepted

Solution code:
N = int(input())
map_T = map(int, input().split())
list_T = list(map_T)
M = int(input())
sumtime = sum(list_T)

for i in range(M):
  map_PX = map(int, input().split())
  list_PX = list(map_PX)
  sumtime_drink = sumtime- list_T[list_PX[0]- 1]+ list_PX[1]
  print(sumtime_drink)

Submission status: Accepted

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


normal_sum = sum(ts)

for _ in range(int(input())):
    no, time = map(int, input().split())
    print(normal_sum - ts[no-1] + time)

Submission status: Accepted

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

# 通常時の合計時間
normal_sum = sum(ts)

for _ in range(int(input())):
    no, time = map(int, input().split())
    print(normal_sum - ts[no-1] + time)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import collections
 
#文字列を一文字ずつ取得したいとき
def inputStrOnebyOne():
    s = list(input())
    return s
 
#整数を一つずつリストに入れる
def inputOnebyOne_Int():
    a = list(int(x) for x in input().split())
    return a
 
def main():
    n = int(input())
    tlist = inputOnebyOne_Int()
    m = int(input())

    ret=0
    for i in range(m):
        p,x = map(int, input().split())
        ret = sum(tlist) - tlist[p-1] + x
        print(ret)
 
if __name__=='__main__':
    main()

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())
    total = sum(t) - t[p-1] + x
    print(total)

Submission status: Accepted

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

total = sum(T)

for i in range(M):
  p,x = list(input().strip().split())
  p = int(p)
  x = int(x)
  print(total - 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())
    a = sum(t) - t[p-1] + x
    print(a)

Submission status: Accepted

Solution code:
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())
	p -= 1
	print(s - T[p] + x)

Submission status: Accepted

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

for j in range(len(T_all)):
    print(T_all[j])

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

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

Submission status: Accepted

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

S=sum(t)

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

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)]
ans = sum(T)
for p, x in px:
  print(ans - (T[p - 1] - x))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
N = int(input())
T = list(map(int, input().split()))
M = int(input())
for i in range(M):
    P, X = map(int, input().split())
    M = [X if j + 1 == P else T[j] for j in range(N)]
    print(sum(M))

Submission status: Accepted

Solution code:
def ABC_50_B():
    N = int(input())
    T = input().split()
    M = int(input())

    for i in range(len(T)):
        T[i] = int(T[i])

    for i in range(M):
        P,X = map(int,input().split())

        Y = T[P-1]
        T[P-1] = X

        print(sum(T))

        T[P-1] = Y




if __name__ == '__main__':

    ABC_50_B()

Submission status: Accepted

Solution code:
n = int(input())
t = list(map(int,input().split()))
m = int(input())
px = [0]*m

for i in range(0,m):
  px[i] = input().split()
  
x = []
#print(px)
tmp = [0]*m

for i in range(0,m):
  tmp = t[:]
  #temp = t[int(px[i][0])-1]
  tmp[int(px[i][0])-1] = int(px[i][1])
  #print(tmp)
  #t[int(px[i][0])-1] = temp
  x.append(sum(tmp))
  
#print(x)

for i in x:
  print(i)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
T=list(map(int,input().split()))
M=int(input())
t=list(T)
for i in range(M):
  P,X=map(int,input().split())
  t[P-1]=X
  print(sum(t))
  t[P-1]=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())

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from math import *

def cin(): # To take limited number of inputs
    return map(int,input().split())

def cins(): # To take space sepreated strings
    return input.split()

def cino(test=False): # To take individual int input (test = False)
    if not test:
        return int(input())
    else: # To take string input (test = True)
        return input()

def cina(): # array input
  return list(map(int,input().split()))

def ssplit(): # multiple string input
    return list(input().split())

def printlist(l): # To print space seperated array
    for i in l:
        print(i,end=" ")

def main():
    n = cino()
    t = cina()
    ans = sum(t)
    k = cino()
    for i in range(k):
      a,b = cin()
      print(ans+(b-t[a-1]))
      


if __name__ == '__main__':
    main()

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

    tmp = T[:]

    tmp[p-1] = x
    print(sum(tmp))

Submission status: Accepted

Solution code:
import copy
n = int(input())
t = list(map(int,input().split()))
m = int(input())
p = [list(map(int,input().split())) for l in range(m)]
for pp in p:
	tmp = copy.copy(t)
	tmp[pp[0]-1] = pp[1]
	print(sum(tmp))

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)]
TSUM = sum(T)
for px in PX:
    print(TSUM + px[1] - T[px[0]-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())
    ans = sum(t) - t[p - 1] + x
    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):
    P, X = map(int, input().split())
    p.append(P)
    x.append(X)

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

Submission status: Accepted

Solution code:
import copy

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

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

import sys
# import time
# import math
# import numpy as np
# import scipy.sparse.csgraph as cs            # csgraph_from_dense(ndarray, null_value=inf), bellman_ford(G, return_predecessors=True), dijkstra, floyd_warshall
# import random                                # random, uniform, randint, randrange, shuffle, sample
# import string                                # ascii_lowercase, ascii_uppercase, ascii_letters, digits, hexdigits
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from datetime import date, datetime          # date.today(), date(year,month,day) => date obj; datetime.now(), datetime(year,month,day,hour,second,microsecond) => datetime obj; subtraction => timedelta obj
# from datetime.datetime import strptime       # strptime('2019/01/01 10:05:20', '%Y/%m/%d/ %H:%M:%S') returns datetime obj
# from datetime import timedelta               # td.days, td.seconds, td.microseconds, td.total_seconds(). abs function is also available.
# from copy import copy, deepcopy              # use deepcopy to copy multi-dimentional matrix without reference
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product, permutations  # product(iter, repeat=n), permutations(iter[,r])
# from itertools import combinations, combinations_with_replacement
# from itertools import accumulate             # accumulate(iter[, f])
# from operator import itemgetter              # itemgetter(1), itemgetter('key')
# from fractions import gcd                    # for Python 3.4 (previous contest @AtCoder)



def main():
    mod = 1000000007                # 10^9+7
    inf = float('inf')              # sys.float_info.max = 1.79...e+308
    # inf = 2 ** 64 - 1             # (for fast JIT compile in PyPy) 1.84...e+19
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())
    
    
    n = ii()
    L = lmi()
    s  = sum(L)
    m = ii()
    for _ in range(m):
        p, x = mi()
        p -= 1
        print(s - L[p] + x)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

sum_T = sum(T)
for problem, time in drinks:
    print(sum_T - T[problem - 1] + time)

Submission status: Accepted

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

Submission status: Accepted

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

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()

#####Shorten#####
def DD(arg): return defaultdict(arg)


#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i])*n**i for i in range(len(str(X))))

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############

N = I()
T = IL()
s = sum(T)
M = I()
D = ILL(M)
for m,t in D:
  P(s-T[m-1]+t)

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

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

Submission status: Accepted

Solution code:
n=int(input())
s=[int(i)for i in input().split()]
d=int(input())
a=0
for i in range(d):
  x,y=map(int,input().split())
  x-=1
  a=s[x]
  s[x]=y
  print(sum(s))
  s[x]=a

Submission status: Accepted

Solution code:
from sys import stdin
def I(): return int(stdin.readline().rstrip())
def LI(): return list(map(int,stdin.readline().rstrip().split()))

n = I()
t = LI()
m = I()
p = []
x = []
for i in range(m):
    tmp = LI()
    p.append(tmp.pop(0)-1)
    x.append(tmp.pop(0))

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

Submission status: Accepted

Solution code:
n,*t=map(int,open(0).read().split());q=t[:n:-1]
while q:print(sum(t[:n])-t[q.pop()-1]+q.pop())

Submission status: Accepted

Solution code:
n,*t=map(int,open(0).read().split());T=sum(t[:n]);q=t[:n:-1]
while q:print(T-t[q.pop()-1]+q.pop())

Submission status: Accepted

Solution code:
I=input;I();t=[int(i)for i in I().split()]
for i in' '*int(input()):p,x=map(int,I().split());print(sum(t)+x-t[p-1])

Submission status: Accepted

Solution code:
I=input
I()
t=[int(i)for i in I().split()]
for i in' '*int(input()):p,x=map(int,I().split());print(sum(t)+x-t[p-1])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
t_list = list(map(int,input().split()))
t_sum = sum(t_list)
m = int(input())
#quetion = [[0]*2 for i in range(m)]
for i in range(m):
    p,x = map(int,input().split())
    print(t_sum - t_list[p-1] + x)

Submission status: Accepted

Solution code:
from copy import copy

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

for px in px_list:
    p, x = px
    tmp_list = copy(t_list)
    tmp_list[p - 1] = x
    print(sum(tmp_list))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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