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

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    T = list(map(int, input().split()))
    m = int(input())

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


if __name__ == '__main__':
    resolve()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

for 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())    
A =  list(map(int,input().split()))
S = sum(A)
m = int(input())    
def pr():
    p,x = map(int,input().split())
    print(S-(A[p-1]-x))
for _ in range(m):
    pr()

Submission status: Accepted

Solution code:
import copy

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

for i in ans:
    print(i)

Submission status: Accepted

Solution code:
n = int(input())
t = list(map(int, input().split()))
m = int(input())
px = [0] * m
for i in range(m):
    px[i] = list(map(int, input().split()))
total = sum(t)
for p, x in px:
    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 i in range(M)]
t = sum(T)
for i in range(len(d)):
    time = t + d[i][1] - T[d[i][0]-1]
    print(time)

Submission status: Accepted

Solution code:
N = int(input())
T = list(map(int,input().split()))
SUM = sum(T)
M = int(input())
drinks = []
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()))
st=sum(t)
m=int(input())
for i in range(m):
  p, x=map(int, input().split())
  print(st+x-t[p-1])

Submission status: Accepted

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

a = sum(T)
for _ in range(M):
    ans = a
    P, X = map(int, input().split())
    ans = ans - T[P-1] + X
    print(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 _ in range(m)]
sumT = sum(T)
for b in d:
    print(sumT - (T[b[0]-1]-b[1]))

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.buffer.readline
MOD = 10**9+7
INF = float('inf')

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




if __name__ == '__main__':
    main()

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 = int(input())
t = list(map(int, input().split()))
m = int(input())
px = [map(int, input().split()) for _ in range(m)]
p, x = [list(i) for i in zip(*px)]
t_c = t[:]
for i in range(m):
    t[p[i]-1] = x[i]
    print(sum(t))
    t[p[i]-1] = t_c[p[i]-1]

Submission status: Accepted

Solution code:
n = int(input())
t_inputs = [int(i) for i in input().split()]
m = int(input())
p_inputs = [[int(j) for j in input().split()]for i in range(m)]

neutral_sum = sum(t_inputs)

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

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:
def main():
    N = int(input())
    T = list(map(int, input().split()))
    M = int(input())
    t_sum = sum(T)
    ans = []
    for i in range(M):
        p, x = map(int, input().split())
        ans.append(t_sum - T[p - 1] + x)
    print('\n'.join(map(str, ans)))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
list_T = list(map(int, input().split()))
m = int(input())
list_PX = [ list(map(int,input().split(" "))) for i in range(m)]
sum_value = sum(list_T)
for i in range(m):
    l = list_PX[i]
    print(sum_value-(list_T[l[0]-1]-l[1]))

Submission status: Accepted

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

s = sum(tl)
for i in range(m):
    p,x = px[i]
    print(s-tl[p-1]+x)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# from math import factorial,sqrt,ceil,gcd
# from itertools import permutations as permus
# from collections import deque,Counter
# import re
# from functools import lru_cache # 簡単メモ化 @lru_cache(maxsize=1000)
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np
# import networkx as nx
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix
# from scipy.special import comb

# slist = "abcdefghijklmnopqrstuvwxyz"
N = int(input())
arrT = [0] + list(map(int,input().split()))
M = int(input())
PandX = [list(map(int,input().split())) for i in range(M)]

total = sum(arrT)
for pm in PandX:
    pnum ,x = pm[0],pm[1]
    print(total - arrT[pnum] + x)

# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する
# print("{:.10f}".format(ans))
# print("{:0=10d}".format(ans))

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

total = sum(T)
for p, x in drink:
    print(total - (T[p - 1] - x))

Submission status: Accepted

Solution code:
import copy

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

Submission status: Accepted

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


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

    print(sum(T)-T[P-1]+X)

Submission status: Accepted

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

Submission status: Accepted

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

sm = sum(T)

for i in range(M):
    P, X =map(int, input().split())
    ans = sm - T[P-1] + X
    print(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 i in range(m)]

for i in range(m):
  temp = t.copy()
  p, x = px[i]
  temp[p-1] = x
  print(sum(temp))

Submission status: Accepted

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

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:
n=int(input())
t=[int(x) for x in input().split()]

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
T = input().split()
M = int(input())
P = [0] * M
X = [0] * M

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

solve_without = 0
solve_without = sum(int(T[a]) for a in range(N))

for ii in range(M):
    solve_with = solve_without - int(T[P[ii] - 1]) + X[ii]
    print(solve_with)

Submission status: Accepted

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

for a in ans:
  print(a)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
t=list(map(int,input().split()))
m=int(input())
px=[map(int, input().split()) for _ in range(m)]
p,x=[list(i) for i in zip(*px)]
total=sum(t)

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

Submission status: Accepted

Solution code:
n=int(input())
t=[0]*n
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())
  
al=sum(t)
for i in range(m):
  print(al-t[p[i]-1]+x[i])

Submission status: Accepted

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

n = int(input())
t = list(map(int, input().split()))
m = int(input())
times = []
for i in range(m):
    p, x = map(int, input().split())
    _t = copy.copy(t)
    _t[p - 1] = x
    times.append(sum(_t))

for time in times:
    print(time)

Submission status: Accepted

Solution code:
n = int(input()) # 入力が1つ
# map(int, input().split()) # 入力が複数
t = [int(i) for i in input().split()] # 配列で数字

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:

def myAnswer(N:int,T:list,M:int,P:list,X:list)-> None:
   #all_time = sum(T)
   for i in range(M):
      print(sum(T) - T[P[i]-1] + X[i])

def modelAnswer():
   tmp=1
def main():
   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)
   myAnswer(N,T[:],M,P[:],X[:])

if __name__ == '__main__':
   main()

Submission status: Accepted

Solution code:
def myAnswer(N:int,T:list,M:int,P:list,X:list)-> None:
   all_time = sum(T)
   for i in range(M):
      print(all_time - T[P[i]-1] + X[i])

def modelAnswer():
   tmp=1
def main():
   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)
   myAnswer(N,T[:],M,P[:],X[:])

if __name__ == '__main__':
   main()

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

Submission status: Accepted

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

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

Submission status: Accepted

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

a = sum(t)
for i in range(m):
    p, x = map(int, input().split())
    ans.append(a - 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 = [list(map(int,input().split())) for i in range(M)]
tmp2 = 0
P = 0
X = 0
c = 0
for a in range(M):
  tmp = PX[a]
  for b in tmp:
    if(c == 0):
      P = b
      c += 1
    else:
      X = b
      c = 0
  tmp2 = T[P - 1]
  T[P - 1] = X
  print(sum(T))
  T[P - 1] = tmp2

Submission status: Accepted

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

Submission status: Accepted

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

ans_org = sum(T)

for i in range(m):
    p, x = [int(x) for x in input().split()]
    for i in range(n):
        ans = ans_org - T[p-1] + x
    print(ans)

Submission status: Accepted

Solution code:
import io

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

Submission status: Accepted

Solution code:
N = int(input())
nums = [int(e) for e in input().split()]
M = int(input())
P = []
for i in range(0,M):
    P.append([int(t) for t in input().split()])
ans = 0
a = 0
for i in range(0,M):
    a = nums[P[i][0]-1]
    nums[P[i][0]-1] = P[i][1]
    for k in range(0,N):
        ans += nums[k]
    print(ans)
    ans = 0
    nums[P[i][0]-1] = a

Submission status: Accepted

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

anss = []
for i in p:
    ans = []
    pp , xx = map(int , i.split())
    for i , n in enumerate(t):
        if i+1 == pp:
            ans.append(xx)
        else:
            ans.append(n)
    anss.append(ans)
for i in anss:
    print(sum(i))

Submission status: Accepted

Solution code:
import collections
import sys
import numpy as np
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
MOD = 10**9+7
import itertools
import math

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.append([p,x])
nodrinkt = sum(t)
for i in range(m):
    diff = t[px[i][0]-1] - px[i][1]
    ans = nodrinkt - diff
    print(ans)

Submission status: Accepted

Solution code:
N = int(input())
T = [0] + [int(x) for x in input().split()]
M = int(input())
s = sum(T)
 
answer = []
for _ in range(M):
  a,b = map(int,input().split())
  answer.append(s+b-T[a])
 
print(*answer,sep='\n')

Submission status: Accepted

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

gokei = sum(T)

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

Submission status: Accepted

Solution code:
import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

n = ni()
t = na()
m = ni()
px = nan(m)

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

Submission status: Accepted

Solution code:
N = int(input())
t_list = [int(t) for t in input().split()]
M = int(input())
table = [[int(i) for i in input().split()] for m in range(M)]

sum1 = 0
for n in range(N):
    sum1 += t_list[n]

for m in range(M):
    sum2 = sum1 - t_list[table[m][0] - 1] + table[m][1]
    print(sum2)

Submission status: Accepted

Solution code:

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

m = int(input())

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

Submission status: Accepted

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

gokei = sum(T)

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

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    default_time = list(map(int, input().split()))
    M = int(input())

    drink_list = list()

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

    for d in drink_list:
        P = d[0]
        X = d[1]
        time = default_time[:]
        time[P - 1] = X
        print(sum(time))
main()

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

sumt = sum(tary)


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

Submission status: Accepted

Solution code:
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))

n = ii()
T = iil()
m = ii()
drink = []
for i in range(m):
    drink.append(iil())

time = sum(T)
for item in drink:
    dif = item[1] - T[item[0]-1]
    print(time + dif)

Submission status: Accepted

Solution code:
n = int(input())
T_list = list(map(int,input().split()))
summ = sum(T_list)
m = int(input())
drinknum = []
drinktime = []
for x in range(m):
    uketsuke = list(map(int,input().split()))
    drinknum.append(uketsuke[0])
    drinktime.append(uketsuke[1])
for x in range(m):
    print(summ - T_list[drinknum[x]-1] + drinktime[x])

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline


def main():
    N = int(input())
    T = list(map(int, input().split()))
    M = int(input())
    P = [None] * M
    X = [None] * M
    for i in range(M):
        P[i], X[i] = map(int, input().split())

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


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
import heapq
import re
from itertools import permutations
from bisect import bisect_left, bisect_right
from collections import Counter, deque
from fractions import gcd
from math import factorial, sqrt
from functools import lru_cache, reduce
INF = 1 << 60
mod = 1000000007
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

# UnionFind
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

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

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

# ダイクストラ
def dijkstra_heap(s, edge, n):
    #始点sから各頂点への最短距離
    d = [10**20] * n
    used = [True] * n #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d

# 素因数分解
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

# 2数の最小公倍数
def lcm(x, y):
    return (x * y) // gcd(x, y)

# リストの要素の最小公倍数
def lcm_list(numbers):
    return reduce(lcm, numbers, 1)

# リストの要素の最大公約数
def gcd_list(numbers):
    return reduce(gcd, numbers)

# ここから書き始める
n = int(input())
t = list(map(int, input().split()))
m = int(input())
total = sum(t)
ans = [0] * m
for i in range(m):
    p, x = map(int, input().split())
    ans[i] = total - 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()))
whole_time = sum(T)
M = int(input())

for i in range(M):
    pi, xi = map(int, input().split())
    print(whole_time - T[pi-1] + xi)

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):
  x, t = map(int, input().split())
  x -= 1
  dif = T[x] - t
  print(total-dif)

Submission status: Accepted

Solution code:
import sys
in1 = sys.stdin.readlines()

#in1 = ['5','7 2 3 8 5','3','4 2','1 7','4 13']

N = int(in1[0])
T_N = list(map(int, in1[1].split()))
M = int(in1[2])
P_M = [None] * M
X_M = [None] * M
idx1 = 0
for PX in in1[3:]:
    P_M[idx1], X_M[idx1] = map(int, PX.split())
    idx1 += 1

sumT = sum(T_N)
for idx1 in range(M):
    print(sumT - T_N[P_M[idx1] - 1] + X_M[idx1])

Submission status: Accepted

Solution code:
n = int(input())
t = list(map(int, input().split()))
m = int(input())
px = list()
for _ in range(m):
    px.append(list(map(int, input().split())))

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

Submission status: Accepted

Solution code:
n = int(input()) #問題数
t = list(map(int, input().split())) #問題
m = int(input()) #ドリンク数
p = [list(map(int, input().split())) for i in range(m)]

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

Submission status: Accepted

Solution code:
def I(): return input()
_=I();t = list(map(int, I().split()))
for _ in range(int(I())):
    s = t[:]
    p, x = map(int, I().split())
    s[p-1] = x
    print(sum(s))

Submission status: Accepted

Solution code:
N = input()
T_list = list(map(int,input().split()))
M = input()
drink_list = []
for i in range(int(M)):
    drink_dict = {}
    P,X = map(int,input().split())
    drink_dict[P] = X
    drink_list.append(drink_dict)

for d in drink_list:
    for p in d.keys():
        sum_time = 0
        for i in range(1,len(T_list)+1):
            if p == i:
                sum_time += d[p]
            else:
                sum_time += T_list[i-1]
        print(sum_time)

Submission status: Accepted

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

total = sum(T)
N = int(input())
ans = []
for i in range(N):
  x,y = map(int, input().split())
  ans.append(total-(T[x-1]-y))
print(*ans, sep='\n')

Submission status: Accepted

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

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

Submission status: Accepted

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

for mi in range(m):
  tt = list(x for x in t)
  p, x = map(int, input().split(' '))
  del tt[p-1]

  res = 0
  for value in tt:
    res += value
  print(res + x)

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(0,M):
    s=Ml[i][0]-1
    f=X[s]
    X[s]=Ml[i][1]
    print(sum(X))
    X[s]=f

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# ABC 050: B – Contest with Drinks Easy
n = int(input())
t = [int(s) for s in input().split()]
m = int(input())
p = []
x = []
for _ in range(m):
    tmp = [int(s) for s in input().split()]
    p.append(tmp[0])
    x.append(tmp[1])

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 = [0] + [int(x) for x in input().split()]
M = int(input())
s = sum(T)

answer = []
for _ in range(M):
    a, b = map(int,input().split())
    answer.append(s+b-T[a])

print(*answer, sep='\n')

Submission status: Accepted

Solution code:
n=int(input())

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

m=int(input())

goukei = sum(t)

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

Submission status: Accepted

Solution code:
N = int(input())
times = list(map(int, input().split()))
M = int(input())
probrems = []

for i in range(M):
    probrems.append([int(i) for i in input().split()])
                         
sum_times = []
                    
for p in range(M):
    init_time = times.copy()
    init_time[probrems[p][0]-1] = probrems[p][1]
    sum_times.append(sum(init_time))

for t in sum_times:
    print(t)

Submission status: Accepted

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

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):
    ans = t[:]
    p, x = map(int, input().split())
    ans[p-1] = x
    #print(ans, sum(ans))
    print(sum(ans))

Submission status: Accepted

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