Problem: You are given sequences A and B consisting of non-negative integers. The lengths of both A and B are N, and the sums of the elements in A and B are equal. The i-th element in A is A_i, and the i-th element in B is B_i.  Tozan and Gezan repeats the following sequence of operations:    * If A and B are equal sequences, terminate the process.   * Otherwise, first Tozan chooses a positive element in A and decrease it by 1.   * Then, Gezan chooses a positive element in B and decrease it by 1.   * Then, give one candy to Takahashi, their pet.  Tozan wants the number of candies given to Takahashi until the process is terminated to be as large as possible, while Gezan wants it to be as small as possible. Find the number of candies given to Takahashi when both of them perform the operations optimally.

Submission attempts (in order):
# -*- coding: utf-8 -*-











import numpy as np

N = int(input())
queA = []
queB = []
for i in range(N):
    A, B = map(int, input().split(" "))
    queA.append(A)
    queB.append(B)

cnt = 0
if np.allclose(A, B):
    print(cnt)



for i in range(N):
    if queA[i] <= queB[i]:
        cnt += queA[i]
        queB[i] -= queA[i]
        queA[i] = 0

は, queA[i] > queB[i]なるqueA[i]を-1するのみになる.


for i in range(N):
    if queA[i] == 0:
        cnt += queB[i]
        queB[i] = 0

print(cnt)

# -*- coding: utf-8 -*-











import numpy as np
def tozan_and_gezan():
    N = int(input())
    queA = []
    queB = []
    for i in range(N):
        A, B = map(int, input().split(" "))
        queA.append(A)
        queB.append(B)

    cnt = 0
    if np.allclose(queA, queB):
        print(cnt)
        return 0

    
    
    for i in range(N):
        if queA[i] <= queB[i]:
            cnt += queA[i]
            queB[i] -= queA[i]
            queA[i] = 0

    if np.allclose(queA, queB):
        print(cnt)
        return 0

    は, queA[i] > queB[i]なるqueA[i]を-1するのみになる.
    
    
    for i in range(N):
        if queA[i] == 0:
            cnt += queB[i]
            queB[i] = 0

    print(cnt)
    return 0

tozan_and_gezan()

# -*- coding: utf-8 -*-











import numpy as np

N = int(input())
queA = []
queB = []
for i in range(N):
    A, B = map(int, input().split(" "))
    queA.append(A)
    queB.append(B)

cnt = 0
if np.allclose(queA, queB):
    print(cnt)
else:
    
    
    for i in range(N):
        if queA[i] <= queB[i]:
            cnt += queA[i]
            queB[i] -= queA[i]
            queA[i] = 0

    は, queA[i] > queB[i]なるqueA[i]を-1するのみになる.
    
    
    for i in range(N):
        if queA[i] == 0:
            cnt += queB[i]
            queB[i] = 0

    print(cnt)

# -*- coding: utf-8 -*-




N = int(input())
queA = []
queB = []
for i in range(N):
    A, B = map(int, input().split(" "))
    queA.append(A)
    queB.append(B)

cnt = 0
if np.allclose(queA, queB):
    print(cnt)
    return 0
else:
    tmp = []
    for i, B in enumerate(queB):
        if queA[i] > B:
            tmp.append(B)
    print(sum(queA) - min(tmp))

# -*- coding: utf-8 -*-











import numpy as np

N = int(input())
queA = []
queB = []
for i in range(N):
    A, B = map(int, input().split(" "))
    queA.append(A)
    queB.append(B)

cnt = 0
if np.allclose(A, B):
    print(cnt)
else:
    
    
    for i in range(N):
        if queA[i] <= queB[i]:
            cnt += queA[i]
            queB[i] -= queA[i]
            queA[i] = 0

    は, queA[i] > queB[i]なるqueA[i]を-1するのみになる.
    
    
    for i in range(N):
        if queA[i] == 0:
            cnt += queB[i]
            queB[i] = 0

    print(cnt)

# -*- coding: utf-8 -*-

inf = 10**20

N = int(input())
s = 0
m = inf
for i in range(N):
    a, b = map(int, input().split(" "))
    if a > b:
        if m < b:
            m = b
    s += a
if m == inf:
    print(0)
else:
    print(s - m)

# -*- coding: utf-8 -*-

inf = 10**20

N = int(input())
s = 0
m = inf
for i in range(N):
    a, b = map(int, input().split(" "))
    if a > b:
        if m > b:
            m = b
    s += a
if m == inf:
    print(0)
else:
    print(s - m)

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Runtime Error

Wrong Answer

Wrong Answer

Accepted