Problem:


Score : 700 points

Problem Statement

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.

Constraints

1 \leq N \leq 2 × 10^5

0 \leq A_i,B_i \leq 10^9(1\leq i\leq N)

The sums of the elements in A and B are equal.

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 B_1
:
A_N B_N

Output

Print the number of candies given to Takahashi when both Tozan and Gezan perform the operations optimally.

Sample Input 1

2
1 2
3 2

Sample Output 1

2

When both Tozan and Gezan perform the operations optimally, the process will proceed as follows:

Tozan decreases A_1 by 1.

Gezan decreases B_1 by 1.

One candy is given to Takahashi.

Tozan decreases A_2 by 1.

Gezan decreases B_1 by 1.

One candy is given to Takahashi.

As A and B are equal, the process is terminated.

Sample Input 2

3
8 3
0 1
4 8

Sample Output 2

9

Sample Input 3

1
1 1

Sample Output 3

0



Sample input:
2
1 2
3 2


Sample output:
2

Submission status: Wrong Answer

Solution code:

import sys

N = int(input())

cab = []

AB = []

flag = True
for i in range(N):
    A,B = map(int,input().split())
    if A!=B:
        flag = False
    AB.append([A,B])

if flag:
    print (0)
    sys.exit()

cab = []
amari = 0
ans = 0

for i in range(N):

    if AB[i][0] <= AB[i][1]:
        ans += AB[i][0]
        amari += AB[i][1] - AB[i][0]

    else:
        cab.append([AB[i][0] - AB[i][1],AB[i][0],AB[i][1]])

cab.sort()

for i in range(len(cab)):

    if amari == cab[i][0]:
        ans += amari
        break
    else:
        amari -= cab[i][0]
        ans += cab[i][1]

print (ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
ab = [list(map(int, input().split())) for i in range(n)]
if all([a == b for a,b in ab]):
  print(0)
  exit()
ans = 0
for a,b in ab:
  if a <= b:
    ans += b
print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin
##  input functions for me
def ria(sep = ''):
    if sep == '' :
        return list(map(int, input().split())) 
    else: return list(map(int, input().split(sep)))
def rsa(sep = ''):
    if sep == '' :
        return input().split() 
    else: return input().split(sep)
def ri(): return int(input())
def rd(): return float(input())
def rs(): return input()
##

## main ##
N = ri()
A = [0] * N
B = [0] * N
for i in range(N):
    A[i], B[i] = map(int, input().split())

res = 0
for i in range(N):
    if(B[i] >= A[i]): res += B[i]

print(res)

Submission status: Wrong Answer

Solution code:
from sys import stdin
##  input functions for me
def ria(sep = ''):
    if sep == '' :
        return list(map(int, input().split())) 
    else: return list(map(int, input().split(sep)))
def rsa(sep = ''):
    if sep == '' :
        return input().split() 
    else: return input().split(sep)
def ri(): return int(input())
def rd(): return float(input())
def rs(): return input()
##

## main ##
N = ri()
A = [0] * N
B = [0] * N
for i in range(N):
    A[i], B[i] = map(int, input().split())

res = 0
for i in range(N):
    if(B[i] > A[i]): res += B[i]

print(res)

Submission status: Wrong Answer

Solution code:
def examC():
    ABC = LI(); ABC.sort()
    judge = ABC[2]*2-ABC[1]-ABC[0]
    ans = judge//2 + (judge%2)*2
    print(ans)
    return

def examD():
    def judge(A,B):
        if A==B:
            return (A-1)*2
        cur = int((A*B)**0.5)
        if cur**2==A*B:
            return (cur-1)*2 -1
        if cur*(cur+1)>=A*B:
            return cur*2 -2
        else:
            return cur*2-1
    Q = I()
    ans = []
    for _ in range(Q):
        a,b = LI()
        ans.append(judge(a,b))
    for v in ans:
        print(v)
    return

def examE():
    N = I()
    cur = 0
    ans = 0; minc = inf
    for i in range(N):
        a, b = LI()
        ans +=a
        if a>=b:
            minc = min(minc,b)
            cur +=a-b
    ans =max(ans-minc,0)
    if cur==0:
        ans = 0
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,inf
mod = 10**9 + 7
inf = 10**18

if __name__ == '__main__':
    examE()

Submission status: Wrong Answer

Solution code:
def examC():
    ABC = LI(); ABC.sort()
    judge = ABC[2]*2-ABC[1]-ABC[0]
    ans = judge//2 + (judge%2)*2
    print(ans)
    return

def examD():
    def judge(A,B):
        if A==B:
            return (A-1)*2
        cur = int((A*B)**0.5)
        if cur**2==A*B:
            return (cur-1)*2 -1
        if cur*(cur+1)>=A*B:
            return cur*2 -2
        else:
            return cur*2-1
    Q = I()
    ans = []
    for _ in range(Q):
        a,b = LI()
        ans.append(judge(a,b))
    for v in ans:
        print(v)
    return

def examE():
    N = I()
    ans = 0; minc = inf
    for i in range(N):
        a, b = LI()
        ans +=a
        if a>=b:
            minc = min(minc,b)
    ans =max(ans-minc,0)
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,inf
mod = 10**9 + 7
inf = 10**18

if __name__ == '__main__':
    examE()

Submission status: Wrong Answer

Solution code:
def examC():
    ABC = LI(); ABC.sort()
    judge = ABC[2]*2-ABC[1]-ABC[0]
    ans = judge//2 + (judge%2)*2
    print(ans)
    return

def examD():
    def judge(A,B):
        if A==B:
            return (A-1)*2
        cur = int((A*B)**0.5)
        if cur**2==A*B:
            return (cur-1)*2 -1
        if cur*(cur+1)>=A*B:
            return cur*2 -2
        else:
            return cur*2-1
    Q = I()
    ans = []
    for _ in range(Q):
        a,b = LI()
        ans.append(judge(a,b))
    for v in ans:
        print(v)
    return

def examE():
    N = I()
    ans = 0; minc = inf
    for i in range(N):
        a, b = LI()
        if a<b:
            ans +=b
        else:
            minc = min(minc,a)
            ans += a
    ans =max(ans-minc,0)
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,inf
mod = 10**9 + 7
inf = 10**18

if __name__ == '__main__':
    examE()

Submission status: Wrong Answer

Solution code:
def examC():
    ABC = LI(); ABC.sort()
    judge = ABC[2]*2-ABC[1]-ABC[0]
    ans = judge//2 + (judge%2)*2
    print(ans)
    return

def examD():
    def judge(A,B):
        if A==B:
            return (A-1)*2
        cur = int((A*B)**0.5)
        if cur**2==A*B:
            return (cur-1)*2 -1
        if cur*(cur+1)>=A*B:
            return cur*2 -2
        else:
            return cur*2-1
    Q = I()
    ans = []
    for _ in range(Q):
        a,b = LI()
        ans.append(judge(a,b))
    for v in ans:
        print(v)
    return

def examE():
    N = I()
    cur = 0
    for i in range(N):
        a, b = LI()
        if a<b:
            cur +=b
    ans = cur
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,inf
mod = 10**9 + 7
inf = 10**18

if __name__ == '__main__':
    examE()

Submission status: Wrong Answer

Solution code:
n = int(input())
s = 0
minb = float("inf")
for _ in range(n):
  a, b = map(int, input().split())
  if a > b:
    minb = min(b, minb)
  s += a
if b == float("inf"):
  print(s - minb)
else:
  print(0)

Submission status: Wrong Answer

Solution code:
n = int(input())
ans = 0
f = False
t = 0
for _ in range(n):
  a, b = map(int, input().split())
  if a < b:
    f = True
    ans += a
  elif a == b:
    t += a
  else:
    ans += a - b
if f:
  ans += t
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
ans = 0
for _ in range(n):
  a, b = map(int, input().split())
  if a < b:
    ans += a
  else:
    ans += a - b
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
res = 0
t = float("inf")
for _ in range(N):
  x, y = map(int, input().split())
  if x >= y: t = min(y, t)
  res += x
print(res - t)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
res = 0
t = float("inf")
for _ in range(N):
  x, y = map(int, input().split())
  if x > y: t = min(y, t)
  res += x
print(res - t)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
res = 0
t = 0
x = []
for _ in range(N):
  u, v = map(int, input().split())
  if u < v:
    res += v
    t += v - u
    u = 0
    v = 0
  x.append((u, v))
#print(t, res)
x.sort(key = lambda x: (x[0] - x[1]))
#print(x)
for i in range(N):
  u, v = x[i]
  #print(u, v, u - t, t, res)
  if u == 0: continue
  if t <= 0: break
  if u - t < 0:
    t -= u
    res += v
  else:
    res += max(v - (u - t), 0)
    t = 0
#print(t)
print(res)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
res = 0
t = 0
x = []
for _ in range(N):
  u, v = map(int, input().split())
  if u < v:
    res += v
    t += v - u
    u = 0
    v = 0
  x.append((u, v))
#print(t)
x.sort(key = lambda x: (x[0] - x[1]))
for i in range(N):
  u, v = x[i]
  if u == 0: continue
  if t <= 0: break
  if u - t < 0:
    t -= u
    res += v
  else:
    res += v - (u - t)
    t = 0
#print(t)
print(res)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
res = 0
for _ in range(N):
  u, v = map(int, input().split())
  if u < v:
    res += v
print(res)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
res = 0
for _ in range(N):
  u, v = map(int, input().split())
  if v > u: res += v
print(res)

Submission status: Wrong Answer

Solution code:
_,*t=open(0).read().split()
t=map(int,t)
s=0
m=9e9
for a,b in zip(t,t):
 s+=a
 if a>b:m=min(m,b)
print(max(0,s-m))

Submission status: Wrong Answer

Solution code:
_,*t=open(0).read().split()
t=map(int,t)
s=0
m=1e18
for a,b in zip(t,t):
 s+=a
 if a>b:m=min(m,b)
print(s-m)

Submission status: Wrong Answer

Solution code:
_,*t=open(0).read().split()
t=map(int,t)
s=0
m=9e9
for a,b in zip(t,t):
 s+=a
 if a>b:m=min(m,b)
print(s-m)

Submission status: Wrong Answer

Solution code:
_,*t=open(0).read().split()
t=map(int,t)
print(sum([a-b,a][a<b]for a,b in zip(t,t)))

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    n=int(input())
    A=[None]*n
    B=[None]*n
    for i in range(n):
        A[i],B[i]=map(int,input().split())

    d=sum(b-a for a,b in zip(A,B) if(a<b))
    s=min(b for a,b in zip(A,B) if(a>=b and a-b<=d))
    print(sum(A)-s)
resolve()

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    n=int(input())
    ans=0
    A=[None]*n
    B=[None]*n
    for i in range(n):
        a,b=map(int,input().split())
        A[i]=a; B[i]=b

    if(A==B):
        print(0)
        return

    d=sum(b-a for a,b in zip(A,B) if(a<b))
    ans=0
    for a,b in zip(A,B):
        if(a-b<d):
            ans+=a
    print(ans+d)
resolve()

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    n=int(input())
    ans=0
    A=[None]*n
    B=[None]*n
    for i in range(n):
        a,b=map(int,input().split())
        A[i]=a; B[i]=b

    if(A==B):
        print(0)
        return

    d=max((a-b,b) for a,b in zip(A,B))[1]
    ans=sum(A)
    print(ans-d)
resolve()

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    n=int(input())
    ans=0
    A=[None]*n
    B=[None]*n
    for i in range(n):
        a,b=map(int,input().split())
        A[i]=a; B[i]=b

    if(A==B):
        print(0)
        return

    ans=0
    for a,b in zip(A,B):
        if(a<b):
            ans+=a
        else:
            ans+=a-b
    print(ans)
resolve()

Submission status: Wrong Answer

Solution code:
N = int(input())
A,B = [],[]
for _ in range(N):
    a,b = map(int,input().split())
    A.append(a)
    B.append(b)
if A == B:
    print(0)
    exit()
ans = 0
for i in range(N):
    if B[i] < A[i]:
        ans = min(ans,-B[i])
print(sum(B) + ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
arr=[list(map(int,input().split())) for _ in range(n)]
arr2=[]
ans=0
for a,b in arr:
  ans+=a
  arr2.append([a-b,b])
arr2=sorted(arr2,reverse=True)
ans-=arr2[0][1]
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
arr=[list(map(int,input().split())) for _ in range(n)]
arr2=[]
ans=0
for a,b in arr:
  ans+=a
  arr2.append([a-b,b])
arr2=sorted(arr2,reverse=True)
ans=-arr2[0][1]
print(ans)

Submission status: Wrong Answer

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

s = 0
m = float('inf')
for i, (A, B) in enumerate(AB) :
    s += A
    if A >= B :
        m = min(m, B)
            
print(s - m)

Submission status: Wrong Answer

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

s = 0
Mi, Mv = 0, 0
for i, (A, B) in enumerate(AB) :
    s += A
    if A >= B :
        if A - B > Mv or (A - B == Mv and A < AB[Mi][0]) :
            Mi = i
            Mv = A - B
            
print(s - AB[Mi][1])

Submission status: Wrong Answer

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

s = 0
Mi, Mv = 0, 0
for i, (A, B) in enumerate(AB) :
    s += A
    if A >= B :
        if A - B > Mv and A < AB[Mi][0]:
            Mi = i
            Mv = A - B
            
print(s - AB[Mi][1])

Submission status: Wrong Answer

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

s = 0
Mi, Mv = 0, 0
for i, (A, B) in enumerate(AB) :
    s += A
    if A >= B :
        if A - B > Mv :
            Mi = i
            Mv = A - B
            
print(s - AB[Mi][1])

Submission status: Wrong Answer

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

s = 0
Mi, Mv = 0, 0
for i, (A, B) in enumerate(AB) :
    s += A
    if A > B :
        if A - B > Mv :
            Mi = i
            Mv = A - B
            
print(s - AB[Mi][1])

Submission status: Wrong Answer

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

s = 0
M = 0
for A, B in AB :
    s += A
    if A >= B :
        M = max(M, B)
        
print(s - M)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(pow(10, 6))

def main():
    n = int(input())
    a, b = [], []
    minb = 10**10
    for _ in range(n):
        _a, _b = map(int, input().split())
        a.append(_a)
        b.append(_b)
        if _a != 0:
            minb = min(minb, _b)
    if a == b:
        print(0)
    else:
        print(sum(a) - minb)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
li = [list(map(int, input().split())) for _ in range(n)]
ans = 0
for i in range(n):
    x, y = li[i][0], li[i][1]
    if x < y:
        ans += x
    else:
        ans += x - y
print(ans)

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline

def main():
    n=int(input())
    min_b=10**10
    s=0
    for _ in range(n):
        a,b=map(int,input().split())
        s+=b
        if a>=b:
            min_b=min(min_b,b)
    print(s-min_b)

main()

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline

def main():
    n=int(input())
    ab=[list(map(int, input().split())) for _ in range(n)]
    ab.sort(key=lambda x:x[0]-x[1])
    #print(ab)
    re=0
    ans=0
    for a,b in ab:
        if a<b:
            ans+=b
            re+=b-a
        if a>=b:
            if re>=a:
                ans+=b
                re+=b-a
            else:
                ans+=b-a+re
        #print(a,b,re,ans)
    print(ans)

main()

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline

def main():
    n=int(input())
    ab=[list(map(int, input().split())) for _ in range(n)]
    ab.sort(key=lambda x:x[0]-x[1])
    #print(ab)
    re=0
    ans=0
    for a,b in ab:
        if a<b:
            ans+=b
            re+=b-a
        if a>=b:
            if re>=a:
                ans+=b
                re-=a
            else:
                ans+=b-a+re
        #print(a,b,re,ans)
    print(ans)

main()

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline

def main():
    n=int(input())
    ab=[list(map(int, input().split())) for _ in range(n)]
    ab.sort(key=lambda x:x[0]-x[1])
    print(ab)
    re=0
    ans=0
    for a,b in ab:
        if a<b:
            ans+=b
            re+=b-a
        if a>=b:
            if re>=a:
                ans+=b
                re-=a
            else:
                ans+=b-a+re
        #print(a,b,re,ans)
    print(ans)

main()

Submission status: Wrong Answer

Solution code:
N = int(input())
a = []
b = []
for i in range(N):
    tmp1, tmp2 = map(int, input().split())
    a.append(tmp1)
    b.append(tmp2)
count = 0
ls_l = [i for i in range(N) if a[i] > b[i]]
ls_m = [i for i in range(N) if a[i] == b[i]]
ls_s = [i for i in range(N) if a[i] < b[i]]

if ls_l != []:
    for idx in ls_m:
        count += a[idx]

for idx in ls_s:
    count += a[idx]

for idx in ls_l:
    count += a[idx]-b[idx]

print(count)

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():

    return

#B
def B():

    return

#C
def C():
    n = I()
    t = LIR(n)
    t.sort(key = lambda x:x[0]-x[1])
    ans = 0
    s = 0
    for i in range(n):
        a,b = t[i]
        if a >= b:
            break
        ans += b
        s += b-a
    for i in range(i,n):
        a,b = t[i]
        if a-s < b:
            ans += b
        s -= a
    print(ans)
    return

#D
def D():

    return

#E
def E():

    return

#F
def F():

    return

#Solve
if __name__ == "__main__":
    C()

Submission status: Wrong Answer

Solution code:
N=int(input())
ab=[[int(i) for i in input().split()] for j in range(N)]
total = sum([sum(row) for row in ab])//2
diff = [row[1] for row in ab if row[0]>row[1]]
if len(diff)==0:
    print(0)
else:
    print(total-max(diff))

Submission status: Wrong Answer

Solution code:
n = int(input())
t = 0
f = 0
for _ in range(n):
  a,b = map(int, input().split())
  if a != b:
    f = 1
  if a <= b:
    t += a
  else:
    t += a-b
print(t*f)

Submission status: Wrong Answer

Solution code:
N = int(input())
A, B = [], []
d = -1
ind = -1
for i in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
    if a > b:
        if b > d:
            d = b
            ind = i

if d == -1:
    print(0)
else:
    print(sum(A) - B[ind])

Submission status: Wrong Answer

Solution code:
N = int(input())
A, B = [], []
d = -1
ind = -1
for i in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
    if a > b:
        if a - b > d:
            d = a - b
            ind = i

if d == -1:
    print(0)
else:
    print(d + sum(A) - A[ind])

Submission status: Wrong Answer

Solution code:
n = int(input())
res = 0
same = 0
for i in range(n):
	a,b = map(int, input().split())
	if a < b:
		res += b
	if a == b:
		same += b
if res == 0:
	print(0)
else:
	print(res + same)

Submission status: Wrong Answer

Solution code:
N=int(input())
ans=0
for i in range(N):
  a,b=map(int,input().split(" "))
  if a<=b: ans+=b
    
print(ans)

Submission status: Wrong Answer

Solution code:
import sys, math, collections, heapq, itertools
F = sys.stdin
def single_input(): return F.readline().strip("\n")
def line_input(): return F.readline().strip("\n").split()
def gcd(a, b):
    a, b = max(a, b), min(a, b)
    while a % b > 0: a, b = b, a % b
    return b
  
def solve():
    N = int(single_input())
    sum = 0
    smallestB = 10 ** 10
    for i in range(N):
        a, b = map(int, line_input())
        sum += a
        if a > b: smallestB = min(smallestB, b)
    print(sum - smallestB)
    return 0
  
if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
import sys, math, collections, heapq, itertools
F = sys.stdin
def single_input(): return F.readline().strip("\n")
def line_input(): return F.readline().strip("\n").split()
def gcd(a, b):
    a, b = max(a, b), min(a, b)
    while a % b > 0: a, b = b, a % b
    return b
  
def solve():
    N = int(single_input())
    array = [list(map(int, line_input())) for i in range(N)]
    num = 0
    for i in range(N):
        if array[i][0] < array[i][1]:
            num += array[i][1]
    print(num)
    return 0
  
if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
N = int(input())
ans = 0
mi = float("inf")
for _ in range(N):
    A, B = map(int, input().split())
    if A>=B:
        mi = min(mi, B)
    ans += B
print(ans - mi if mi != float("inf") else 0)

Submission status: Wrong Answer

Solution code:
N = int(input())
ans = 0
for _ in range(N):
    A, B = map(int, input().split())
    if A>=B:
        ans += A-B
    else:
        ans += A
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=[]
B=[]
for i in range(N):
    a,b=map(int,input().split())
    A.append(a)
    B.append(b)
ans=0
for i in range(N):
    if A[i]<B[i]:
        ans+=B[i]
print(ans)

Submission status: Wrong Answer

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

def main():
    for a,b in ab:
        if a != b:
            break
    else:
        return 0
    ans = 0
    for a,b in ab:
        if a<=b:
            ans += a
        else:
            ans += a-b
    return ans
print(main())

Submission status: Wrong Answer

Solution code:
N = int(input())
cnt = 0
for i in range(N):
  a,b = list(map(int,input().split()))
  if a > b:
    cnt += a-b
  elif a < b:
    cnt += a
  else:
    continue
    
print(cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
mini = 10**10
s = 0
for i in range(n):
	a, b = map(int, input().split())
	s += a
	if a > b:
		mini = min(mini, b)
print(s-mini)

Submission status: Wrong Answer

Solution code:
from collections import deque

n = int(input())
ans = 0
e = []
proc_score = 0
for i in range(n):
	a, b = map(int, input().split())
	if a > b:
		e.append([a, a-b, -b])
	else:
		ans += a
		proc_score += b-a

if proc_score == 0:
	print(0)
else:

	#exc: aの値とa-bを格納→a-bで昇順にソート
	e.sort(key=lambda x: (x[1], x[2]))
	exc = deque(e)
	while True:
		if exc[0][1] == proc_score:
			ans += proc_score
			break
		else:
			proc_score -= exc[0][1]+1
			ans += exc[0][0]
			proc_score += 1
			exc.popleft()

	print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque

n = int(input())
ans = 0
e = []
proc_score = 0
for i in range(n):
	a, b = map(int, input().split())
	if a >= b:
		e.append([a, a-b, -b])
	else:
		ans += a
		proc_score += b-a

if proc_score == 0:
	print(0)
else:

	#exc: aの値とa-bを格納→a-bで昇順にソート
	e.sort(key=lambda x: (x[1], x[2]))
	exc = deque(e)
	while True:
		if exc[0][1] == proc_score:
			ans += proc_score
			break
		else:
			proc_score -= exc[0][1]+1
			ans += exc[0][0]
			proc_score += 1
			exc.popleft()

	print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque

n = int(input())
ans = 0
e = []
proc_score = 0
for i in range(n):
	a, b = map(int, input().split())
	if a >= b:
		e.append([a, a-b])
	else:
		ans += a
		proc_score += b-a

if proc_score == 0:
	print(0)
else:

	#exc: aの値とa-bを格納→a-bで昇順にソート
	e.sort(key=lambda x: x[1])
	exc = deque(e)
	while True:
		if exc[0][1] == proc_score:
			ans += proc_score
			break
		else:
			proc_score -= exc[0][1]+1
			ans += exc[0][0]
			proc_score += 1
			exc.popleft()

	print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque

n = int(input())
ans = 0
e = []
proc_score = 0
for i in range(n):
	a, b = map(int, input().split())
	if a >= b:
		e.append([a, a-b])
	else:
		ans += a
		proc_score += b-a

if proc_score == 0:
	print(0)

#exc: aの値とa-bを格納→a-bで昇順にソート
e.sort(key=lambda x: x[1])
exc = deque(e)
while True:
	if exc[0][1] == proc_score:
		ans += proc_score
		break
	else:
		proc_score -= exc[0][1]+1
		ans += exc[0][0]
		proc_score += 1
		exc.popleft()

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def main():
    N = int(input())
    A, B = [], []

    total = 0
    for _ in range(N):
        a, b = map(int, input().split())
        A.append(a)
        B.append(b)
        total += a

    r = INF
    for a, b in zip(A, B):
        if a == 0 and b == 0:
            continue
        if b <= a:
            r = min(r, b)
    print(total - r)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def main():
    N = int(input())
    A, B = [], []

    total = 0
    for _ in range(N):
        a, b = map(int, input().split())
        A.append(a)
        B.append(b)
        total += a

    r = INF
    for a, b in zip(A, B):
        if b <= a:
            r = min(r, b)
    print(total - r)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
ans,num = 0,0
for _ in range(n):
	a,b = (int(i) for i in input().split())
	if a<b: ans+=b
	elif a==b: num,ans = num+1,ans+b
if n-num: print(ans)
else: print(0)

Submission status: Wrong Answer

Solution code:
n = int(input())
ans,num = 0,0
for _ in range(n):
	a,b = (int(i) for i in input().split())
	if a<b: ans+=b
	elif a==b: num+=1
if n-num: print(ans)
else: print(0)

Submission status: Wrong Answer

Solution code:
n = int(input())

result = 0
#a = [0 for _ in range(n)]
#b = [0 for _ in range(n)]
for i in range(n):
    a, b = map(int, input().split())
    if b > a:
        result += b

print(result)

Submission status: Wrong Answer

Solution code:
N = int(input())

plus_min, minus, total = 10**10, 0, 0
for _ in range(N):
    a, b = map(int, input().split())
    total += a
    if a > b:
        plus_min = min(plus_min, b)
    elif a < b:
        minus += a

if minus == 0:
    print(0)
    exit()

print(int(total - plus_min))

Submission status: Wrong Answer

Solution code:
N = int(input())

plus, minus, equal = 0, 0, 0
for _ in range(N):
    a, b = map(int, input().split())
    if a > b:
        plus += a - b
    elif a < b:
        minus += a
    else:
        equal += a

if minus == 0:
    print(0)
    exit()

print(int(minus + plus + equal))

Submission status: Wrong Answer

Solution code:
n = int(input())
aSum = 0
abSum = 0
bMin = float('inf')

for i in range(n):
    a, b = list(map(int, input().split()))

    abSum += a
    if a > b:
        bMin = min(bMin, b)
    else:
        aSum += a

if aSum == 0:
    print(0)
else:
    print(abSum - bMin)

Submission status: Wrong Answer

Solution code:
n = int(input())
aSum1 = 0
aSum2 = 0

for i in range(n):
    a, b = list(map(int, input().split()))

    if a <= b:
        aSum1 += a
    else:
        aSum2 += (a - b)

if aSum2 == 0:
    print(0)
else:
    print(aSum1 + aSum2)

Submission status: Wrong Answer

Solution code:
n = int(input())

s = 0
m = 0
same = True
for _ in range(n):
    a,b = map(int, input().split())
    if a > b:
        m = max(m, b)
    s += a
    same &= a==b
if same:
    m = s
print(s-m)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = 0
C = -1
for i in range(N):
    A, B = map(int, input().split())
    S += A
    if A <= B:
        B -= A
        A = 0
    if A != 0 and (B < C or C < 0):
        C = B

print(S - C)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = 0
C = -1
for i in range(N):
    A, B = map(int, input().split())
    S += A
    if (A > B and B < C) or C < 0:
        C = B

print(S - C)