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, os, math, bisect, itertools, collections, heapq, queue, copy, array

# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
# from decimal import Decimal
# from collections import defaultdict, deque

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

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


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    T = il()
    M = ii()
    sm = sum(T)

    for m in range(M):
        P, X = il()
        print(sm-(T[P-1]-X))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
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):
    ans = 0
    ans += sum(T[:P[i] - 1])
    ans += X[i]
    ans += sum(T[P[i]:])
    print(ans)

Submission status: Accepted

Solution code:
N = int(input())
T = list(map(int,input().split()))
M = int(input())
for i in range(M):
    Pi,Xi=map(int,input().split())
    a = T[Pi-1]
    T[Pi-1] = Xi
    b = 0
    for j in range(N):
        b = b + T[j]
    print(b)
    T[Pi-1] = a

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)
a=0
for i in range(n):
    a+=t[i]
for i in range(m):
    print(a-t[p[i]-1]+x[i])

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import copy
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())
    t_temp = copy.copy(t)
    t_temp[p - 1] = x
    print(sum(t_temp))

Submission status: Accepted

Solution code:
N = int(input())
T = [int(TN) for TN in input().split()]
SumT = sum(T)
M = int(input())
PX = [[] for TM in range(0,M)]
for TM in range(0,M):
    PX[TM] = [int(TPX) for TPX in input().split()]
for TM in range(0,M):
    print(SumT-T[PX[TM][0]-1]+PX[TM][1])

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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


def read():
    N = int(input().strip())
    T = list(map(int, input().strip().split()))
    M = int(input().strip())
    PX = []
    for i in range(M):
        p, x = map(int, input().strip().split())
        PX.append((p, x))
    return N, T, M, PX


def solve(N, T, M, PX):
    S = sum(T)
    for p, x in PX:
        ans = S - T[p-1] + x
        print(ans)


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))

Submission status: Accepted

Solution code:
#B - Contest with Drinks Easy
N = int(input())
T = list(map(int,input().split()))
M = int(input())
P = []
X = []
for _ in range(M):
    Pi,Xi = map(int,input().split())
    P.append(Pi)
    X.append(Xi)

A = []
for i in range(M):
    T_copy = T.copy()
    T_copy[P[i]-1] = X[i]
    A.append(sum(T_copy))    

for k in range(M):
    print(A[k])

Submission status: Accepted

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

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, v = list(map(int, input().split()))
  print(s - t[p-1] + v)

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


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

Submission status: Accepted

Solution code:
import copy

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

Submission status: Accepted

Solution code:
N = int(input())
Nl = list(map(int, input().split()))
s = sum(Nl)

M = int(input())
for i in range(M):
    Ml = list(map(int, input().split()))
    print(s + Ml[1] - Nl[Ml[0] - 1])

Submission status: Accepted

Solution code:
# row = [int(x) for x in input().rstrip().split(" ")]
# n = int(input().rstrip())
# s = input().rstrip()

def resolve():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip())
    ts = [int(x) for x in input().rstrip().split(" ")]
    original_time = sum(ts)
    m = int(input().rstrip())
    for i in range(m):
        p, x = [int(x) for x in input().rstrip().split(" ")]
        print(original_time - ts[p-1] + x)

if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
# B - Contest with Drinks Easy
def main():
    import copy
    _ = int(input())
    t = list(map(int, input().split()))
    m = int(input())
    px = [input().split() for i in range(m)]
    

    for i in range(m):
        tt = copy.copy(t)
        tt[int(px[i][0])-1] = int(px[i][1])
        print(sum(tt)) 


if __name__ ==  "__main__":
    main()

Submission status: Accepted

Solution code:
num_prob = int(input())
prob = input()
new = prob.split()
sum = 0

for j in new:
  sum += int(j)

  
num_drinks = int(input())
for i in range(num_drinks):
  line = input()
  new_line = line.split()
  if int(new_line[1]) != int(new[int(new_line[0])-1]):
    temp = sum - int(new[int(new_line[0])-1]) + int(new_line[1])
    print(temp)
  else:
    print(sum)

Submission status: Accepted

Solution code:
num_problems = input()
a = input()
total = 0
seconds_per = a.split()
for i in seconds_per:
  total += int(i)
drinks = int(input())
for i in range(drinks):
  b = input()
  c = b.split()
  question = int(c[0])
  change = int(c[1])
  new = total-int(seconds_per[question-1]) + change
  print(new)

Submission status: Accepted

Solution code:
ProNum = int(input())
time = input()
time = (time.split())
TotalTime = 0

for t in time:
  TotalTime += int(t)
                  
DrinkNum = int(input())

for d in range(DrinkNum):
  line = input()
  line = line.split()
  diff = int(line[1]) - int(time[int(line[0])-1])
  print(TotalTime+diff)

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

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(m):
    tmp=t[:]
    tmp[drink[i][0]-1]=drink[i][1]
    print(sum(tmp))

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

tot_t = sum(t)

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

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)]
time=sum(t)
for i in range(m):
    print(time-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())
l = [list(map(int,input().split())) for i in range(m)]
a,b = [list(i) for i in zip(*l)]
for i in range(m):
    s = list(t)
    j = a[i] - 1
    s[j] = b[i]
    print(sum(s))

Submission status: Accepted

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

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

Submission status: Accepted

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

for PX in PX:
    ans = T[:]
    ans[PX[0]] = PX[1]
    print(sum(ans))

Submission status: Accepted

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

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

for i in ans:
    print(i)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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())
px = [tuple(map(int,input().split())) for _ in range(M)]

SUM = sum(T)

for i in range(M):
  p,x=px[i]
  print(SUM - T[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:
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)

Submission status: Accepted

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

for h in range(m):
    s = 0
    for j in range(n):
        if j == px[h][0]:
            s += px[h][1]
        else:
            s += t[j]
    print(s)

Submission status: Accepted

Solution code:
N = int(input())
T = list(map(lambda t: int(t), input().split(" ")))
M = int(input())
P = []
T_new = []
T_diff = []
for i in range(M):
  tmp = input().split(" ")
  P.append(int(tmp[0]) - 1)
  T_new.append(int(tmp[1]))
  T_diff.append(T_new[i] - T[P[i]])

T_sum = sum(T)
print("\n".join([str(T_sum + t_d) for t_d in T_diff]))

Submission status: Accepted

Solution code:
n = int(input())

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

m = int(input())

drink_num_time = []
drink_time = []

for i in range(m):
    drink_num_time.append(list(map(int,input().split())))

normal_time = sum(time_list)


for i in range(m):
    drink_time.append(normal_time+drink_num_time[i][1]-time_list[(drink_num_time[i][0])-1])

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

Submission status: Accepted

Solution code:
import sys


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

n = inint()
T = inintl()
m = inint()

for i in range(m):
    p, x = inintm()
    t = T[p-1]
    T[p-1] = x
    print(sum(T))
    T[p-1] = t

Submission status: Accepted

Solution code:
n = int(input())
t =tuple(map(int,input().split()))
m = int(input())
for i in range(m):
  s =list(t)
  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()))
sum_ = sum(T)
M = int(input())
ans = list()
for i in range(M) :
    P, X = map(int,input().split())
    gap = T[P-1] - X
    ans.append(sum_ - gap)

for i in range(len(ans)):
    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)]
sumt = sum(t)
for i in range(m):
    print(sumt - t[px[i][0]-1] +px[i][1])

Submission status: Accepted

Solution code:
n=int(input())
t=list(map(int, input().strip().split()))
m=int(input())
px = []
for i in range(m):
    array = list(map(int, input().strip().split()))
    px.append(array)
wa=0
for i in range(n):
    wa+=t[i]

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

Submission status: Accepted

Solution code:
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

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

    print(S - T[p - 1] + x)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]

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

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

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)
INF = float('inf')

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

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)
INF = float('inf')

N = int(input())
T = list(map(int, input().split()))
M = int(input())
for _ in range(M):
    P, X = map(int, input().split())
    ans = 0
    for i in range(N):
        if i + 1 == P:
            ans += X
        else:
            ans += T[i]
    print(ans)

Submission status: Accepted

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

for an in ans:
    print(an)

Submission status: Accepted

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


for i in range(M):
    cnt = 0
    for j in range(len(T)):
        if px[i][0] == j+1 :
            cnt += px[i][1]
        else:
            cnt += T[j]
    print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(M):
    ans = sum(T) + P[i][1] - T[P[i][0]-1]
    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 _ in range(M)]

tsum = sum(T)

for px in PX:
    p = px[0]
    x = px[1]

    t = tsum - T[p - 1] + x
    print(t)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
lsT = list(map(int,input().split()))
M = int(input())
sum1 = sum(lsT)
lsP = []
for i in range(M):
    lsP.append(list(map(int,input().split())))

for i in range(M):
    print(sum1-lsT[lsP[i][0]-1]+lsP[i][1])

Submission status: Accepted

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

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

Submission status: Accepted

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

sum_t = sum(t)

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

for v in res:
    print(v)

Submission status: Accepted

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

Ans = []

for _ in range(M):
    P,X = map(int, input().split())
    Ans.append(sum(T) - T[P-1] + X)

for ans in Ans:
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

pxn = []
for _ in range(m):
  p, x = map(int, input().split())
  pxn.append([p, x])
  
for p in pxn:
  print(sum(tn) - tn[p[0]-1] + p[1])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# 2020/07/25
# AtCoder Beginner Contest 050 - B

# Input
n = int(input())
t = list(map(int,input().split()))
m = int(input())
tsum = sum(t)

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

Submission status: Accepted

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n = I()
T = readInts()
sumT = sum(T)
p_ = I()
for i in range(p_):
    p,x = readInts()
    print(sumT - T[p-1] + x)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

S = sum(T)
for i in range(m):
    p, x = PX[i]
    ans = S - T[p] + x
    print(ans)

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))

N = ini()
T = inl()
M = ini()


def solve():
    tsum = sum(T)
    for i in range(M):
        p, x = inm()
        p -= 1
        ans = tsum - T[p] + x
        print(ans)


solve()

Submission status: Accepted

Solution code:
def solve():
  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] += y-T[x-1]
  return ans
print(*solve(),sep='\n')

Submission status: Accepted

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

ans = sum(t)
for p,x in px:
    a = ans-t[p-1]+x
    print(a)

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(M):
    a,b=map(int,input().split())
    SS=S-T[a-1]+b
    print(SS)

Submission status: Accepted

Solution code:
n = int(input())

times = list(map(int, input().split(' ')))

summary = sum(times)

m = int(input())

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
a=[int(i) for i in input().split()]
m=int(input())
d=0
for i in range(0,len(a)):
        d=d+a[i]
for i in range(m):
    b,c=[int(i) for i in input().split()]
    z=a[b-1]
    e=(d-(z))+(c)
    print(e)

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 sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N = int(readline())
    T = list(map(int, readline().split()))
    M, *PX = map(int, read().split())

    s = sum(T)
    ans = [0] * M
    for i, (p, x) in enumerate(zip(*[iter(PX)] * 2)):
        p -= 1
        ans[i] = s + (x - T[p])

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

    return


if __name__ == '__main__':
    main()

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

Submission status: Accepted

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

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

Submission status: Accepted

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

M = int(input())

dic ={}
base = sum(T)

for i in range(M):
  a,b = map(int,input().split())
  print(base - T[a-1]+b)

Submission status: Accepted

Solution code:
a=int(input())
List1 = list(map(int, input().split()))
Row = int(input())
List2 = []
for i in range (Row):
  List2.append(list(map(int, input().split())))
res = [0]*Row
for i in range(Row):
  for j in range(a):
    if j+1 == List2[i][0]:
      res[i] += List2[i][1]
    else:
      res[i] += List1[j]
for element in res:
  print(element)

Submission status: Accepted

Solution code:
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N = I()
    T = LI()
    M = I()
    PX = [LI() for _ in range(M)]

    sum_T = sum(T)
    for px in PX:
        P, X = px
        print(sum_T - T[P - 1] + X)

if __name__ == '__main__':
    resolve()

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 = tuple(map(int,input().split()))
M = int(input())
for i in range(M):
    P,X = map(int,input().split())
    ans = list(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):
    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])