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())
PX = [list(map(int, input().split())) for _ in range(m)]

total = sum(T)

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
INF = float("inf")


def solve(N: int, T: "List[int]", M: int, P: "List[int]", X: "List[int]"):
    tot = sum(T)
    for i in range(M):
        print(tot-T[P[i]-1]+X[i])
    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:
import copy
n = int(input())
t = [int(i) for i in input().split()]
m = int(input())
sum_t = sum(t)
for _ in range(m):
  p, x = map(int, input().split())  
  print(sum_t - (t[p-1] - x))

Submission status: Accepted

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

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

lst = t.copy()

for i in range(m):
    lst[p[i][0]-1] = p[i][1]
    print(sum(lst))
    lst = t.copy()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def main():
    N = INT()
    T = LIST()
    M = INT()
    L = [LIST() for i in range(M)]
    ans = []
    for i in range(M):
        T_copy = deepcopy(T)
        p = L[i][0]
        x = L[i][1]
        T_copy[p-1] = x
        print(sum(T_copy))






if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n = int(input())
ta = input().split()
t = []
for i in range(len(ta)):
    t.append(int(ta[i]))
m = int(input())
p = []
x = []
for i in range(m):
    ta = input().split()
    p = int(ta[0])
    x = int(ta[1])

    total = 0
    for j in range(len(t)):
        if j + 1 == p:
            total = total + x
        else:
            total = total + t[j]

    print(total)

Submission status: Accepted

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

for Pi, Xi in PX:
    d = Xi - T[Pi - 1]
    print(sum(T) + d)

Submission status: Accepted

Solution code:
#python3

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

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

Submission status: Accepted

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

Submission status: Accepted

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

a=sum(t)
for i in range(m):
    j=d[i][0]
    ans=a-t[j-1]+d[i][1]

    print(ans)

Submission status: Accepted

Solution code:
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    n=INT()
    ts=LIST()
    m=INT()
    xs=[0]*m
    for i in range(m):
        p,x=INTM()
        xs[i]=ts[p-1]-x
    tst=sum(ts)
    for i in range(m):
        #print(xs[i])
        print(tst-xs[i])
    #print(ts)
if __name__ == '__main__':
    do()

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

point = []
for i in range(M):
  a = sum(T) - T[PX[i][0] - 1] + PX[i][1]
  point.append(a)

for j in point:
  print(j)

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

Submission status: Accepted

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


for g, h in p:
	ti = t.copy()
	ti[g-1] = h
	print(sum(ti))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# AtCoder Beginner Contest 050 - B
# -*- encoding: UTF-8 -*-
n = int(input())
tlist = list(map(int, input().split()))
m = int(input())
mlist = []
for i in range(m):
  p_x = list(map(int, input().split()))
  mlist.append(p_x)

base = 0
for i in tlist:
  base = base + i

for p_x in mlist:
  p, x = p_x
  s = x - tlist[p-1]
  print(base + s)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin

sr = lambda: stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
T = lr()
M = ir()
total = sum(T)
for _ in range(M):
    p, x = lr()
    result = total - T[p-1] + x
    print(result)

# 22

Submission status: Accepted

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

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
times = [int(i) for i in input().split()]
M = int(input())
p_x_list = [[int(i) for i in input().split()] for _ in range(M)]

for i, p_x in enumerate(p_x_list):
    p = p_x[0]
    x = p_x[1]
    # pは1から始まっているのでindexとして扱うために-1する
    print(sum(times) - times[p-1] + x)

Submission status: Accepted

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

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

for a in ans:
    print(a)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
T = [int(x) for x in input().split()]
M = int(input())
PX = []
for _ in range(M):
    PX.append([int(x) for x in input().split()])
total = sum(T)
ans = []
for i in range(M):
    P, X = PX[i]
    temp = total - T[P - 1] + X
    ans.append(temp)
for j in ans:
    print(j)

Submission status: Accepted

Solution code:
n = int(input())
T = [int(i) for i in input().split()]
m = int(input())
P = []
X = []
for i in range(m):
    p, x = map(int, input().split())
    P.append(p)
    X.append(x)

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import copy

n = int(input())

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

m = int(input())

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

tpList =  copy.copy(tList)
for j in pList:
  tpList[j[0]-1]=j[1]
  print(sum(tpList))
  tpList = copy.copy(tList)

Submission status: Accepted

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

Submission status: Accepted

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

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

t_total = sum(t)

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

Submission status: Accepted

Solution code:
#50b
N = int(input())
T_list = [int(e) for e in input().split()]

T_sum = sum(T_list)

M = int(input())

for i in range(M):
    P,X = map(int, input().split())
    print(T_sum - T_list[P-1] + X)

Submission status: Accepted

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

Submission status: Accepted

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

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

tot = sum(T)
for i in range(m):
    ans = tot - T[P[i]-1] + X[i]
    print(ans)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
n = int(input())
times = list(map(int, input().split()))
m = int(input())
drinks = [list(map(int, input().split())) for _ in range(m)]

times_sum = sum(times)

for p, t in drinks:
    print(times_sum - times[p-1] + t)

Submission status: Accepted

Solution code:
n = int(input())
times = list(map(int, input().split()))
m = int(input())
drinks = [list(map(int, input().split())) for _ in range(m)]

for p, t in drinks:
    time = times.copy()
    time[p-1] = t
    print(sum(time))

Submission status: Accepted

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

drink=[]
for _ in range(m):
    a,b=map(int,input().split())
    drink.append(s + b -li[a-1])

print(*drink,sep='\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):
  temp=T[:]
  p,x=map(int,input().split())
  temp[p-1]=x
  print(sum(temp))

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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


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

Submission status: Accepted

Solution code:
n=int(input())
t=[0]+[int(i) for i in input().split()]
m=int(input())
p=[[int(j) for j in input().split()] for i in range(m)]

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

Submission status: Accepted

Solution code:
N = int(input())
T=[int(x) for x in 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:
import copy

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

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

tmp = [print(i) for i in ans]

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):
    tmpT=T[:PX[i][0]-1]+T[PX[i][0]:]
    print(sum(tmpT)+PX[i][1])

Submission status: Accepted

Solution code:
import copy


N = int(input())
*T, = map(int, input().split())

M = int(input())

A = []
for _ in range(M):
    P,X = map(int, input().split())
    A.append([P,X])


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

Submission status: Accepted

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

for i in range(m):
  ans=0
  for j in range(1,n+1):
    if j==dl[i][0]:
      ans+=dl[i][1]
    else:
      ans+=pl[j-1]
  print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
M = int(input())
ans = []
for i in range(M):
  p, x = map(int, input().split())
  copy_A = A.copy()
  copy_A[p-1] = x
  ans.append(sum(copy_A))
for a in ans:
  print(a)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
l=input().rstrip().split()
m=int(input())
ans=[]
A=0
for i in range(m):
    p,x=[int(i) for i in input().rstrip().split()]
    for j in range(len(l)):
        if p-1==j:
            A+=x
        else:
            A+=int(l[j])
    ans.append(A)
    A=0

for i in range(len(ans)):
    print(ans[i])

Submission status: Accepted

Solution code:
n=int(input())
ti=input().split(' ')
times=[]
for i in ti:
    times.append(int(i))
summ=sum(times)
nu=int(input())
for i in range(0,nu):
    inps=input().split(' ')
    tempsum=summ
    tempsum=tempsum-times[int(inps[0])-1]
    tempsum+=int(inps[1])
    print(tempsum)

Submission status: Accepted

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

Submission status: Accepted

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

M = int(input())
for _ in range(M):
    i, x = map(int, input().split())
    ans = sum_all - T[i - 1] + x
    print(str(ans))

Submission status: Accepted

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

T_SUM = sum(T)
for a in A:
	print(T_SUM-a)

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):
    s=[]
    for j in range(n):
        s.append(t[j])
    s[p[i]-1] = x[i]
    print(sum(s))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input=sys.stdin.readline

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

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

Submission status: Accepted

Solution code:
import sys

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

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

for i in ans:
    print(i)

Submission status: Accepted

Solution code:
from fractions import gcd
# from datetime import date, timedelta
from heapq import*
import math
from collections import defaultdict, Counter, deque
from bisect import *
import itertools
import sys
sys.setrecursionlimit(10 ** 7)
MOD = 10 ** 9 + 7
# input = sys.stdin.readline


def main():
    n = int(input())
    t = list(map(int, input().split()))
    m = int(input())
    px = [list(map(int, input().split())) for i in range(m)]

    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)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:

import copy

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 = copy.copy(t)
    l[p-1] = x
#    print(t)
#    print(l)
    print(sum(l))

Submission status: Accepted

Solution code:
N = int(input())
T = [int(i) for i in 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())
drink = [tuple(map(int, input().split())) for _ in range(m)]
for i in range(m):
    ans = 0
    for j in range(n):
        if drink[i][0] == j + 1:
            ans += drink[i][1]
        else:
            ans += t[j]
    print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf')
ans = 0 ;count = 0 ;pro = 1

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import itertools#これは色々使える組み込み関数みたいなやつ
import math#数学的計算はこれでいける。普通に0.5乗しても計算可能
#w=input()
i=0
N=int(input())
#eH, W=input().split()
#S=input()
#T=input()
#S_list=list(S)
T_list=  list(map(int, input().split(" ")))
M=int(input())
drink_list = [list(map(int, input().split(" ")))for i in range(M)]
#print(T_list[1])
#H=int(H)
#W=int(W)
#C=int(C)
#K=int(K)
T_dummy_list=[]
pixel_list=[]
total=0
t=0
#センテンスを暗記するのではなく、まずinput()を書いて、膨らます感じで記述する。すると#思考の流れ通りに書ける。素晴らしい！
#for i in range(K):
# ID_list.append(i+1)
#print(ID_list)
#for i in range(H)
#この下の行が二次元リストの読み込
#intを消して記号を読み込めるようにしたしかしこれでは文字列から読み込んでいるのと同じ
#pixel_list =  [list(input())for i in range(H)]
#for i in range(H):
#  ppixel_list=list(input())
#  
#print(pixel_list)
i=0
j=0
#high_pixel_list =[['' for i in range(W)]for j in range(2*H)]
#print(high_pixel_list)
#print(pixel_list[0][1])#行　列の順番にかっこが並んでいる

#整数二次元配列を読み込む時のやり方
#gate_list =  [list(map(int, input().split(" ")))for i in range(M)]
#センテンスを暗記するのではなく、まずinput()を書いて、膨らます感じで記述する。すると#思考の流れ通りに書ける。素晴らしい！
for i in range(M):
 total=0
 T_dummy_list[:]=T_list[:]
 T_dummy_list[drink_list[i][0]-1]=drink_list[i][1]
 #print(T_dummy_list)
 for j in range(N):
    #print(T_dummy_list[j])
    t=T_dummy_list[j]
    total=total+t

 print(total)

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 a in ans:
    print(a)

Submission status: Accepted

Solution code:
import sys
import numpy as np 

I = np.array(sys.stdin.read().split(), dtype=np.int64)
n = I[0]
t = I[1:1+n]
m = I[1+n]
p, x = I[2+n:].reshape(m, 2).T 

def main():
    default = np.sum(t)
    res = default + (x - t[p-1])
    return res

if __name__ == '__main__':
    ans = main()
    print(*ans, sep='\n')

Submission status: Accepted

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

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

Submission status: Accepted

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

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

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-a[p-1]+x)

Submission status: Accepted

Solution code:
n = int(input())
ls_t = list(map(int, input().split()))
m = int(input())
ls_px = [[int(_) for _ in input().split()] for _ in range(m)]

time = sum(ls_t)

for i in range(m):
    p = ls_px[i][0] - 1
    x = ls_px[i][1]
    print(time - ls_t[p] + x)

Submission status: Accepted

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

for i in l:
    print(sum(t)-t[i[0]-1]+i[1])

Submission status: Accepted

Solution code:
n = int(input())
T = tuple(map(int,input().split()))
m = int(input())
drinks = [list(map(int,input().split())) for _ in range(m)]
ans_list = []
# python はmutable objectは参照渡しにimutable object(tuple等)は値渡しになる
def swap(p,x):
  temp = list(T)
  temp[p - 1] = x
  return temp
for i in range(m):
  p,x = drinks[i][0],drinks[i][1]
  new = swap(p,x)
  ans_list.append(sum(new))
for ans in ans_list:
  print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

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 = t[:]
    ans[p-1] = x
    print(sum(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):
    x1,y1=[int(i) for i in input().split()]
    P.append(x1)
    X.append(y1)

output=[]
for j in range(M):
    tmp=T.copy()
    tmp[P[j]-1]=X[j]
    output.append(str(sum(tmp)))

print('\n'.join(output))

Submission status: Accepted

Solution code:
import sys
from functools import reduce
import copy
import math
from pprint import pprint
import collections
import bisect
import itertools


sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def int_inputs(num_of_input):
    ins = [int(input()) for i in range(num_of_input)]
    return ins


def solve(T, PX):
    T = string_to_int(T)
    DRINKS = list(map(string_to_int, PX))
    sum_t = reduce(lambda acc, x: acc+x, T, 0)

    ret = []
    for d in DRINKS:
        i = d[0] - 1
        x = d[1]
        ret.append(sum_t - (T[i] - x))
    return ret


def string_to_int(string):
    return list(map(lambda x: int(x), string.split()))


if __name__ == "__main__":
    input()
    T = input()
    M = int(input())
    ret = solve(T, inputs(M))
    for r in ret:
        print(r)

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

total_time = sum(T)

for i in range(M):
    t = PX[i][0]-1

    print(total_time - (T[t] - PX[i][1]))

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

Submission status: Accepted

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

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

count = 0
for i in range(len(T)):
    count += T[i]

c = count

for i in range(M):
    count = c
    count += X[i]
    count -= T[P[i] - 1]
    print(count)

Submission status: Accepted

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

for r in res:
    print(r)

Submission status: Accepted

Solution code:
_ = input()
lst = [int(i) for i in input().split()]
m = int(input())
mlist = [[int(i) for i in input().split()] for _ in range(m)]

for i in mlist:
  tmp = lst.copy()
  tmp[i[0]-1] = i[1]
  print(sum(tmp))

Submission status: Accepted

Solution code:
import copy

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


m = int(input())
for _ in range(m):
    idx, value = map(int, input().split())
    print(sum_t - t[idx - 1] + value)

Submission status: Accepted

Solution code:
import copy

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


n = int(input())
for i in range(n):
    idx, value = map(int, input().split())
    T = copy.deepcopy(t)
    t[idx - 1] = value
    print(sum(t))
    t = copy.deepcopy(T)