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 = [int(x) for x in 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 _ in range(m):
    temp_list = list(t_list)
    p,x = map(int,input().split())

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

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):
    print(Tsum-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 = []
for i in range(M):
  P.append(list(map(int,input().split())))
  
SU = sum(T)

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

Submission status: Accepted

Solution code:
N = int(input())
T = [(i,int(x)) for i,x in enumerate(input().split(),1)]
M = int(input())
px = [input().split() for _ in range(M)]
for p,x in px:
  print(sum(int(x) if int(p) == i else t for i,t in T))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

num = sum(t)

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

Submission status: Accepted

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

sm = sum(T)
for p,x in drinks:
    print(sm - 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 = input().split()

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

    print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

base_value = sum(T_list)

for i in range(M):
    print(base_value - (T_list[M_list[i][0]-1] - M_list[i][1]))

Submission status: Accepted

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

Submission status: Accepted

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

for _ in ans:
    print(_)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Thu Aug 23 22:02:16 2018
ABC050B
@author: maezawa
"""

n = int(input())
t = list(map(int, input().split()))
m = int(input())
p = []
x = []
for _ in range(m):
    pi, xi = list(map(int, input().split()))
    p.append(pi)
    x.append(xi)
    
standard = sum(t)
for i in range(m):
    stime = standard - (t[p[i]-1]-x[i])
    print(stime)

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

Submission status: Accepted

Solution code:
from copy import copy

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

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

M=int(input())

a=[]
for k in range(M):
    a.append(list(map(int,input().split())))

cal=sum(t)

for j in range(M):
    print(cal - t[a[j][0]-1] + a[j][1])

Submission status: Accepted

Solution code:
n = int(input())
tList = input().split(' ')

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

m = int(input())
pList = []
xList = []

for j in range(m):
    p, x = input().split(' ')
    pList.append(int(p))
    xList.append(int(x))

for k in range(m):
    tListCopy = list(tList)
    tListCopy[pList[k]-1] = xList[k]
    print(sum(tListCopy))

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
#50b
#n　問題数
n = int(input())
#t 時間
t = [int(i) for i in input().split()]
#m ドリンクの種類
m = int(input())
ans = []

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

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

Submission status: Accepted

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

Submission status: Accepted

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

def main():
    n = int(input())
    t_list = list(map(int, input().split()))
    m = int(input())
    drink_list = [list(map(int, input().split())) for _ in range(m)]

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# input
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):
    temp = T[P[i][0] - 1]
    T[P[i][0] - 1] = P[i][1]
    print(sum(T))
    T[P[i][0] - 1] = temp

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n=int(input())
d={i+1:j for (i,j) in enumerate(map(int,input().split()))}
m=int(input())
for _ in range(m):
  a,b=map(int,input().split())
  s=sum([j if i!=a else b  for (i,j) in d.items()])
  print(s)

Submission status: Accepted

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

ans=sum(A)

for i in range(M):
  a,b=map(int,input().split())
  cnt=A[a-1]-b
  print(ans-cnt)

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

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

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 = 0
    for j in range(n):
        if j == (p - 1):
            total += x
        else:
            total += t[j]
    print(total)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

S=sum(t)
m=int(input())
ans=[0]*m

for i in range(m):
    a,b=map(int,input().split())
    ans[i]=S+b-t[a-1]

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

ans = []
for i in range(m):
    #どのドリンクを飲むか
    p, x = p_x[i]
    buf = 0
    for j in range(n):
        #何番の問題にかかる時間を加算するか
        if j == (p-1):
            buf += x
        else:
            buf += t[j]
    ans.append(buf)
for x in ans:
    print(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)]

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 = [int(i) for i in input().split()]
m = int(input())
p = []
x = []
for i in range(m):
    tmp = [int(i) for i in input().split()]
    p.append(tmp[0])
    x.append(tmp[1])

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
input()
T = list(map(int,input().split()))
s = sum(T)
M = int(input())
ans = []
for i in range(M):
    l = input().split()
    ans.append(s+int(l[1])-T[int(l[0])-1])
for a in ans:
    print(a)

Submission status: Accepted

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


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

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    Tt = [int(i) for i in input().split(" ")]
    M = int(input())
    for i in range(M):
        T = Tt[:]
        P , X = map(int,input().split(" "))
        T[P-1] = X
        print(sum(T))

if __name__ == '__main__':
    main()

Submission status: Accepted

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    T = [int(x) for x in input().split()]
    M = int(input())
    PX = [[int(x) for x in input().split()] for _ in range(M)]
    for P, X in PX:
        t = T[:]
        t[P - 1] = X
        print(sum(t))


if __name__ == '__main__':
    main()

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

Submission status: Accepted

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

n = int(input())
T = list(map(int, input().split()))
m = int(input())
A = [list(map(int, input().split())) for _ in range(m)]
_sum = sum(T)

for a in A:
    print(_sum - T[a[0]-1] + a[1])

Submission status: Accepted

Solution code:
N = int(input())
T_list = list(map(int, input().split()))
M = int(input())
PX_list = []
for _ in range(M):
    PX_list.append(tuple(map(int, input().split())))
    
for i in PX_list:
    print(sum(T_list) + i[1] - T_list[i[0]-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)]
k=sum(t)
for i in range(m):
    print(k-t[px[i][0]-1]+px[i][1])

Submission status: Accepted

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

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

# 予め基準になる合計値を出しておく
sum1 = sum(tests)

for i in range(M):
    p, x = map(int, input().split())
    # 先に出しておいた基準からの差分で算出
    print(sum1 + (x - tests[p-1]))

Submission status: Accepted

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

import copy

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

for i in range(M):
    tmp = copy.deepcopy(tests)
    p, x = map(int, input().split())
    tmp[p-1] = x
    print(sum(tmp))

Submission status: Accepted

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

for i in range(M):
  time=0
  P=input().split()
  drink=int(P[0])
  for k in range(N):
    if(k+1 == drink):
      time+=int(P[1])
    else:
      time+=int(T[k])
  print(time)

Submission status: Accepted

Solution code:
import copy

total_problem = int(input())
time_list = list(map(int, input().split()))
total_drinks = int(input())

drinks = []

for i in range(total_drinks):
  drinks.append(list(map(int, input().split())))

output_list = []
for i in range(total_drinks):
  output_list = copy.deepcopy(time_list)

  output_list[drinks[i][0] - 1] = drinks[i][1]
  print(sum(output_list))

Submission status: Accepted

Solution code:
n=int(input())
t=[int(i) for i in input().split()]
x=t
m=int(input())
px=[]
for i in range(m):
    px.append([int(j) for j in input().split()])
#print("____")
#print("px==",px)
#print("x==",x)
#print("____")
for i in range(m):
    c=t[px[i][0]-1]
    t[px[i][0]-1]=px[i][1]
    print(sum(t))
    t[px[i][0]-1]=c

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(raw_input())
T = map(int,raw_input().split())
S = sum(T)
M = int(raw_input())
for i in range(M):
  Pi, Xi = map(int,raw_input().split())
  print S + (Xi - T[Pi-1])

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):
  pi, xi = map(int, input().split())
  p.append(pi)
  x.append(xi)
t_sum = 0
for i in range(n):
  t_sum = t_sum + t[i]
for i in range(m):
  print(t_sum+x[i]-t[p[i]-1])

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)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
TimeList = input().split(" ")
M = int(input())

for i in range(M):
    array = input().split(" ")
    sum = 0
    for j in range(N):
        sum += int(TimeList[j])
    print(sum + int(array[1]) - int(TimeList[int(array[0])-1]))

Submission status: Accepted

Solution code:
from copy import copy
N = int(input())
problems = list(map(int,input().split()))
M = int(input())
for i in range(M):
    problems_temp = copy(problems)
    drink = list(map(int,input().split()))
    problems_temp[drink[0]-1] = drink[1]
    print(sum(problems_temp))

Submission status: Accepted

Solution code:
n = int(input())
t = list(map(int,input().split()))
m = int(input())
a = []
for _ in range(m):
    a.append(list(map(int,input().split())))
for i in range(m):
    j = a[i][0]-1
    print('{}'.format(sum(t)- t[j] + a[i][1]))

Submission status: Accepted

Solution code:
N = int(input())

t = input().split()
T = []
for i in range(N):
    T.append(int(t[i]))

M = int(input())

time = []
total = sum(T)
for k in range(M):
    p,x = (int(i) for i in input().split())
    time.append(total - T[p-1] + x)

for i in range(M):
    print(time[i])

Submission status: Accepted

Solution code:
import copy

n = int(input())
array = [int(x) for x in input().split()]
nn = int(input())
res = []
for i in range(nn):
    aarraayy = copy.copy(array)
    x, y = map(int, input().split())
    aarraayy[x-1] = y
    res.append(sum(aarraayy))

for j in res:
    print(j)

Submission status: Accepted

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


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N = int(input())
ts = list(map(int,input().split()))
M = int(input())
src = [tuple(map(int,input().split())) for i in range(M)]

sm = sum(ts)
for p,x in src:
    print(sm - ts[p-1] + x)

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

Submission status: Accepted

Solution code:
from sys import stdin

N = int(stdin.readline().rstrip())
T = stdin.readline().rstrip().split()
M = int(stdin.readline().rstrip())
P = [stdin.readline().rstrip().split() for _ in range(M)]

T_num = [int(n) for n in T]
P_num = [list(map(int, P_in)) for P_in in P]

for i in range(len(P_num)):
    list_tmp = T_num[:]
    index = P_num[i][0] - 1
    val = P_num[i][1]
    list_tmp[index] = val
    print(sum(list_tmp))

Submission status: Accepted

Solution code:
N = int(input())
ps = list(map(int,input().split()))
M = int(input())
ds = [tuple(map(int,input().split())) for i in range(M)]

time = sum(ps)
for p,x in ds:
    p -= 1
    print(time - ps[p] + x)

Submission status: Accepted

Solution code:
N = int(input())
T = list(map(int, input().split()))
M = int(input())
sum_ = sum(T)
idx = 0
max_ = -1
for _ 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,X = [],[]
for i in range(M):
    p,x = map(int,input().split())
    P.append(p-1)
    X.append(x)
sumT = sum(T)
for i in range(M):
    print(sumT + X[i] - T[P[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,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())
D = [list(map(int, input().split())) for k in range(M)]
S = sum(T)

for k in range(M):
    print(S-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())
ans = list()

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

Submission status: Accepted

Solution code:
N = int(input())
Time = list(map(int, input().split(' ')))
M = int(input())
Drink = []
for i in range(M):
    p, x = map(int, input().split(' '))
    tmp = Time[::]
    tmp.pop(p-1)
    s = sum(tmp) + x
    Drink.append(s)
for i in Drink:
    print(i)

Submission status: Accepted

Solution code:
input()
*a,=map(int,input().split())
for _ in[0]*int(input()):i,x=map(int,input().split());print(sum(a)-a[~-i]+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 = list(map(int, input().split()))
    print(sum(t) - t[p-1] + x)

Submission status: Accepted

Solution code:
N = int(input())

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

M = int(input())

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

tsum=sum(T[:N])

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

Submission status: Accepted

Solution code:
import math
import sys

def getinputdata():

    # 配列初期化
    array_result = []
    
    data = input()

    array_result.append(data.split(" "))

    flg = 1

    try:


        while flg:

            data = input()

            array_temp = []

            if(data != ""):
                
                array_result.append(data.split(" "))

                flg = 1

            else:

                flg = 0
    finally:


        return array_result





arr_data = getinputdata()

#問題数
n = int(arr_data[0][0])

#ドリンク数
m = int(arr_data[2][0])

arr01 = list(map(int, arr_data[1]))


#print(n, m, arr01)

for i in range(3, 3 + m):
    
    arr02 = arr01.copy()
    
    arr02.pop(int(arr_data[i][0])-1)
    
    #追加
    arr02.append(int(arr_data[i][1]))
    
    print(sum(arr02))

Submission status: Accepted

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

St = sum(t)

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

Submission status: Accepted

Solution code:
n = int(raw_input())
solvetime = map(int, raw_input().split())
solvesum = 0
for i in range(0, n):
	solvesum = solvesum + solvetime[i]

m = int(raw_input())
for i in range(0, m):
	inpt = map(int, raw_input().split())
	print solvesum - solvetime[inpt[0]-1] + inpt[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 = 0
    for j in range(N):
        if j == P-1:
            ans += X
        else:
            ans += T[j]
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
t = list(map(int,input().split()))
m = int(input())
px = [[int(i) for i in 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)

Submission status: Accepted

Solution code:

n=int(input())

t=input()
t=t.split()

m=int(input())
px=[]
su=[]
for i in range(m):
    px.append(input().split())
    o=t[int(px[-1][0])-1]
    t[int(px[-1][0])-1]=int(px[-1][1])
    temp=0
    for i in t:
        temp=temp+int(i)
    su.append(temp)
    t[int(px[-1][0])-1]=o
    
for i in su:
    print(i)

Submission status: Accepted

Solution code:
N=int(input())
T= list(map(int,input().split())) ##Time for each prob

M=int(input())
P=[None for i in range(M)]
X=[None for i in range(M)]

for i in range(M):
    P[i],X[i]= input().split()

P= list(map(int,P)) ##Index of drink
X= list(map(int,X)) ##Time for problem after drink


for i in range (M):
    temp= T[P[i]-1]

    T[P[i]-1]=X[i]
    print(sum(T))
    T[P[i] - 1]=temp

Submission status: Accepted

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

# AtCoder Beginner Contest
# Problem B

if __name__ == '__main__':
    problem_count = int(input())
    elapsed_times = list(map(int, input().split()))
    drink_kind_count = int(input())
    effects = [list(map(int, input().split())) for i in range(drink_kind_count)]

    total_elapsed_time = sum(elapsed_times)

    for problem_p, new_elapsed_time, in effects:
        print(total_elapsed_time + (new_elapsed_time - elapsed_times[problem_p - 1]))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N=int(input())
T=[int(i) for i in 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())
S=sum(T)
for i in range(M):
    print(S-T[P[i]-1]+X[i])

Submission status: Accepted

Solution code:
n = int(input())
t = [int(i) for i in input().split()]
m = int(input())
d = [[int(i) for i in input().split()] for i in range(m)]
x = sum(t)
for i in range(m):
	y = d[i][1]-t[d[i][0]-1]
	print(x+y)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
N=input()
T=list(map(int,input().split()))
M=int(input())
go=[]
for c in range(M):
    P,X=map(int,input().split())
    place=P-1
    result=T[place]
    Result=result-X
    ans=sum(T)-Result
    go.append(ans)
for Ans in go:
    print(Ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
time = [0]*N
tmp = input().split()
total = 0
for i in range(N):
  time[i] = int(tmp[i])
  total += time[i]
M = int(input())
for j in range(M):
  tmp = input().split()
  print(total+int(tmp[1])-time[(int(tmp[0])-1)])

Submission status: Accepted

Solution code:
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

n = ni()
t = na()
m = ni()
p = [na() for _ in range(m)]

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

Submission status: Accepted

Solution code:
from copy import deepcopy

N = int(input())
T = [int(n) for n in input().split()]
M = int(input())
PX = []
for _ in range(M):
    PX.append(tuple([int(n) for n in input().split()]))

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

Submission status: Accepted

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


solve()

Submission status: Accepted

Solution code:
def calc(lis, m_lis):
    copy_list = lis[:]
    copy_list[m_lis[0] - 1] = m_lis[1]
    print(sum(copy_list))


int(input())
lis = list(map(int, input().split()))
[calc(lis, i) for i in [list(map(int, input().split()))
                        for i in range(int(input()))]]

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
ti=list(map(int,input().split()))
m=int(input())
pi=[0for i in range(m)]
xi=[0for i in range(m)]
for i in range(m):
  pi[i],xi[i]=map(int,input().split())

#print(pi)
#print(ti)
for i in range(m):
  time=0
  for j in range(n):
    if(j==pi[i]-1):
      time+=xi[i]
    else:
      time+=ti[j]
    #print(time)
  print(time)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
T = [0] + [int(i) for i in input().split()]
M = int(input())
D = [[int(i) for i in input().split()] for j in range(M)]
 
for p,x in D:
  tmp = T[p]
  T[p] = x
  print(sum(T))
  T[p] = tmp