Problem:


Score : 400 points

Problem Statement

On a two-dimensional plane, there are N red points and N blue points.
The coordinates of the i-th red point are (a_i, b_i), and the coordinates of the i-th blue point are (c_i, d_i).

A red point and a blue point can form a friendly pair when, the x-coordinate of the red point is smaller than that of the blue point, and the y-coordinate of the red point is also smaller than that of the blue point.

At most how many friendly pairs can you form? Note that a point cannot belong to multiple pairs.

Constraints

All input values are integers.

1 \leq N \leq 100

0 \leq a_i, b_i, c_i, d_i < 2N

a_1, a_2, ..., a_N, c_1, c_2, ..., c_N are all different.

b_1, b_2, ..., b_N, d_1, d_2, ..., d_N are all different.

Input

Input is given from Standard Input in the following format:

N
a_1 b_1
a_2 b_2
:
a_N b_N
c_1 d_1
c_2 d_2
:
c_N d_N

Output

Print the maximum number of friendly pairs.

Sample Input 1

3
2 0
3 1
1 3
4 2
0 4
5 5

Sample Output 1

2

For example, you can pair (2, 0) and (4, 2), then (3, 1) and (5, 5).

Sample Input 2

3
0 0
1 1
5 2
2 3
3 4
4 5

Sample Output 2

2

For example, you can pair (0, 0) and (2, 3), then (1, 1) and (3, 4).

Sample Input 3

2
2 2
3 3
0 0
1 1

Sample Output 3

0

It is possible that no pair can be formed.

Sample Input 4

5
0 0
7 3
2 2
4 8
1 6
8 5
6 9
5 4
9 1
3 7

Sample Output 4

5

Sample Input 5

5
0 0
1 1
5 5
6 6
7 7
2 2
3 3
4 4
8 8
9 9

Sample Output 5

4



Sample input:
3
2 0
3 1
1 3
4 2
0 4
5 5


Sample output:
2

Submission status: Wrong Answer

Solution code:
import math
import sys
from pprint import pprint

def distance(a,b):
    return math.sqrt((a[0]-b[0])**2 + (a[1]-b[1])**2)

def solve(reds, blues):
    ans = []
    # for blue in blues:
    #     pprint(reds)
    #     pprint(blues)
    #     print("------")
    #     red_ans = reds[0]
    #     min_d = sys.maxsize
    #     for red in reds:
    #         print("now checking {} and {}".format(red, blue))
    #         if blue[0] > red[0] and blue[1] > red[1] and (red, blue) not in ans:
    #             min_d = 1
    #             break
    #             # d = distance(red, blue)
    #             # if min_d > d:
    #             #     red_ans = red
    #             #     min_d = d
    #     if min_d != sys.maxsize:
    #         ans.append((red_ans, blue))
    #         blues.remove(blue)
    #         reds.remove(red_ans)
    # while len(blues) != 0:
    #     blue = blues.pop()
    #     print("-----")
    #     pprint(reds)
    #     pprint(blues)
    #     red_ans = reds[0]
    #     min_d = sys.maxsize
    #     for red in reds:
    #         if blue[0] > red[0] and blue[1] > red[1] and (red, blue) not in ans:
    #             d = distance(red, blue)
    #             if min_d > d:
    #                 red_ans = red
    #                 min_d = d
    #     if min_d != sys.maxsize:
    #         print("{} <-> {}".format(red_ans, blue))
    #         ans.append((red_ans, blue))
    #         reds.remove(red_ans)
    # pprint(reds)
    # pprint(blues)
    while len(reds) != 0:
        red = reds.pop()
        # print("-----")
        # pprint(reds)
        # pprint(blues)
        blue_ans = blues[0]
        min_d = sys.maxsize
        for blue in blues:
            if blue[0] > red[0] and blue[1] > red[1] and (red, blue) not in ans:
                d = distance(red, blue)
                if min_d > d:
                    blue_ans = blue
                    min_d = d
        if min_d != sys.maxsize:
            # print("{} <-> {}".format(red, blue_ans))
            ans.append((red, blue_ans))
            blues.remove(blue_ans)
    # pprint(ans)
    return len(ans)

if __name__ == '__main__':
    N = int(input())
    reds = []
    for i in range(N):
        a,b = list(map(lambda x: int(x), input().split(" ")))
        reds.append((a,b))
    blues = []
    for i in range(N):
        c,d = list(map(lambda x: int(x), input().split(" ")))
        blues.append((c,d))
    ans = []
    reds.sort()
    blues.sort()
    blues.reverse()
    ans = solve(reds, blues)
    print(ans)
    # while len(blues) == 0:
    #     blue = blues.pop()

Submission status: Wrong Answer

Solution code:
import sys

stdin = sys.stdin

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

n = ni()
red = []
for _ in range(n):
    red.append(na())
blue = []
for _ in range(n):
    blue.append(na())

red_1 = sorted(red)
blue_1 = sorted(blue)
ans_1 = 0

for i in red_1:
    for j in blue_1:
        if i[0] < j[0] and i[1] < j[1]:
            ans_1 += 1
            blue_1.remove(j)
            break

from operator import itemgetter
red.sort(key=itemgetter(1))
blue.sort(key=itemgetter(1))
ans_2 = 0

for i in red:
    for j in blue:
        if i[0] < j[0] and i[1] < j[1]:
            ans_2 += 1
            blue.remove(j)
            break
if ans_1 > ans_2:
    print(ans_1)
else:
    print(ans_2)

Submission status: Wrong Answer

Solution code:
n = int(input())
reds = []
for i in range(n):
    a, b = map(int, input().split())
    reds.append((a, b))

reds = sorted(reds, key=lambda tup: tup[0] + tup[1], reverse=True)
#print(reds)

blues = []
for i in range(n):
    blues.append(tuple(map(int, input().split())))

blues = sorted(blues, key=lambda tup: tup[0] + tup[1], reverse=True)
#print(blues)

result = 0
#reds_begin = 0
flgs = []
for i in range(n):
    flgs.append(False)
for blue in blues:
    for i in range(n):
        red = reds[i]
        a, b = red[0], red[1]
        c, d = blue[0], blue[1]
        if (a < c) and (b < d) and flgs[i] == False:
            flgs[i] = True
            result += 1
            break

print(result)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = []
b = []
ans = 0
for i in range(0, n):
    a.append(list(map(int, input().split(" "))))
for i in range(0, n):
    b.append(list(map(int, input().split(" "))))
a.sort(reverse=True)
b.sort(reverse=True)
i=0
while i<=len(b)-1:
    kappuru = []
    for j in range(0, len(a)):
        if a[j][0] < b[i][0] and a[j][1] < b[i][1]:
            kappuru.append(j)
    if len(kappuru)>0:
        c=[]
        for k in range(0, len(kappuru)):
            c.append(a[kappuru[k]][1])
        m=c.index(max(c))
        ans+=1
        del a[kappuru[m]]
        del b[i]
        i=-1
    i+=1
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
Flag = 0
TmpNum = 0
Count = 0
Red = [[0 for i in range(3)]  for j in range(N)]
Blue= [[0 for i in range(3)]  for j in range(N)]

for i in range(N):
    Tmp = input().rstrip().split(' ')
    Red[i][0] = int(Tmp[0])
    Red[i][1] = int(Tmp[1])
    Red[i][2] = Red[i][0]**2+Red[i][1]**2

for i in range(N):
    Tmp = input().rstrip().split(' ')
    Blue[i][0] = int(Tmp[0])
    Blue[i][1] = int(Tmp[1])
    Blue[i][2] = Blue[i][0]**2+Blue[i][1]**2

Red = sorted(Red, key=lambda x: x[2],  reverse=True)          
Blue = sorted(Blue, key=lambda x: x[2])     
    
Count = 0
for i in range(N):
    TmpRx = Red[i][0]
    TmpRy = Red[i][1]
    
    for i2 in range(N):
        TmpBx = Blue[i2][0]
        TmpBy = Blue[i2][1]
        if TmpBx >= 0:
            if (TmpRx < TmpBx) and (TmpRy < TmpBy):
                Count += 1
                Blue[i2][0] = -1
                Blue[i2][1] = -1
                Red[i][0] = 1000
                Red[i][1] = 1000
                break

#        if TmpBx < 101:
#            if (TmpRx < TmpBx) and (TmpRy < TmpBy):
#                Count += 1
#                Blue[i2][0] = 1000
#                Blue[i2][1] = 1000
#                Red[i][0] = 1000
#                Red[i][1] = 1000
#                break

print(Count)


############################################

Submission status: Wrong Answer

Solution code:
n = int(input())
red = [0]*n
blue = [0]*n
for i in range(n):
    red[i] = list(map(int,input().split()))
for i in range(n):
    blue[i] = list(map(int,input().split()))
red.sort()
blue.sort()
p = [[] for j in range(n)]
q = []
for i in range(n):
    for j in range(n):
        if(red[i][0]<blue[j][0] and red[i][1]<blue[j][1]):
            p[i].append(j)
            q.append(j)
q = list(set(q))
o = 0
qq = []
for i in q:
    c = 0
    for j in p:
        c+=j.count(i)
    qq.append([c,i])
qq.sort()
for i in qq:
    for j in range(n):
        if i[1] in p[j]:
            p[j] = [-1]
            o += 1
            break
print(o)

Submission status: Wrong Answer

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

N = int(input())
ab = []
for i in range(0,N):
    data1,data2 = input().split()
    ab.append([int(data1),int(data2)])

cd = []
for i in range(0,N):
    data1,data2 = input().split()
    cd.append([int(data1),int(data2)])

ab_sort = sorted(ab)
cd_sort = sorted(cd)
ab_sort_r1 = sorted(ab)
ab_sort_r1.reverse()
cd_sort_r1 = sorted(cd)
cd_sort_r1.reverse()
ab_sort_r2 = sorted(ab)
ab_sort_r2.reverse()
cd_sort2 = sorted(cd)


pair = 0
del_list = []
for i in cd_sort_r1:
    n = 0
    for j in ab_sort_r1:
        if i[0] > j[0] and i[1] > j[1]:
            pair = pair + 1
            break
        else:
            n = n + 1
    if n < int(len(ab_sort_r1)):
        del(ab_sort_r1[n])

pair2 = 0
for i in ab_sort_r2:
    n = 0
    for j in cd_sort2:
        if i[0] < j[0] and i[1] < j[1]:
            pair2 = pair2 + 1
            break
        else:
            n = n + 1
    if n < int(len(cd_sort2)):
        del(cd_sort2[n])


if pair2 < pair:
    print(pair)
else:
    print(pair2)

Submission status: Wrong Answer

Solution code:
# NG 15-

N = int(input())

R = []
for i in range(N):
    x, y = list(map(int, input().split()))
    R.append((x, y))

B = []
for i in range(N):
    x, y = list(map(int, input().split()))
    B.append((x, y))

R.sort(key=lambda a:a[0]**2+a[1]**2, reverse=True)
B.sort(key=lambda a:a[0]**2+a[1]**2, reverse=True)

ans = 0
for pos in B:
    x, y = pos
    for pos2 in R:
        x2, y2 = pos2
        if x2<x and y2<y:
            R.remove(pos2)
            ans += 1
            break

print(ans)

Submission status: Wrong Answer

Solution code:
import copy

def main():
    N = int(input())
    abList = []
    cdList = []
    for i in range(N):
        [a, b] = list(map(int, input().split(' ')))
        abList.append( (a+b, a, b) )
    for i in range(N):
        [c, d] = list(map(int, input().split(' ')))
        cdList.append( (c+d, c, d) )
    abList.sort()
    cdList.sort()
    cdList2 = copy.copy( cdList )
    ans = 0
    for (_, a, b) in abList:
        for i in range( len(cdList) ):
            (_, c, d) = cdList[i]
            if a < c and b < d:
                cdList.pop(i)
                ans += 1
                break
    ans2 = 0
    abList.reverse()
    cdList.reverse()
    for (_, a, b) in abList:
        for i in range( len(cdList2) ):
            (_, c, d) = cdList2[i]
            if a < c and b < d:
                cdList2.pop(i)
                ans2 += 1
                break
    print( max(ans, ans2) )
main()

Submission status: Wrong Answer

Solution code:
N = int(input())
R = [list(map(int, input().split())) for i in range(N)]
B = [list(map(int, input().split())) for i in range(N)]
for i in range(len(B)):
    c = 0
    for r in R:
        if B[i][0] > r[0] and B[i][1] > r[1]:
            c += 1
    B[i].append(c)
B = sorted(B, key = lambda x:x[2])
ans = 0
for b in B:
    for i, r in enumerate(R):
        if b[0] > r[0] and b[1] > r[1]:
            ans += 1
            R.pop(i)
            break
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    red = []
    for i in range(N):
        x,y = [int(i) for i in input().split()]
        red.append([x,y])
    blue = []
    for i in range(N):
        x,y = [int(i) for i in input().split()]
        blue.append([x,y])
    red.sort(reverse=True)
    blue.sort(reverse=True)
    #print(red)
    #print(blue)
    pair = 0
    for a in range(N):
        flag = False
        for i in range(N):
            for j in range(N):
                if(red[i][0] <= blue[j][0] and red[i][1] <= blue[j][1]):
                    pair = pair + 1
                    flag = True
                    #print(f'{red[i]} {blue[j]}')
                    blue[j][0] = -10000000000
                    blue[j][1] = -10000000000
                    red[j][0] =  10000000000
                    red[j][1] = 10000000000
                    break
                
        if flag:
            break
    print(pair)
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# -- coding: utf-8 --
N = int(input())
red = []
for i in range(N):
    red.append(list(map(int, input().split(' '))))
blue = []
for i in range(N):
    blue.append(list(map(int, input().split(' '))))
mred = sorted(red)
mblue = sorted(blue, reverse=True)
count = 0
minsum = 100000
cand = 1000000
for i in range(N):
    last = mred.pop()
    for num, l in enumerate(mblue[:]):
        tmpsum = (l[0] - last[0]) + (l[1] - last[1])
        if last[0] < l[0] and last[1] < l[1] and min(minsum, tmpsum) == tmpsum:
            cand = num
            minsum = tmpsum

    if cand < len(mblue):
        count += 1
        mblue.pop(cand)
    cand = 1000000
    minsum = 1000000

print(count)

Submission status: Wrong Answer

Solution code:

n = int(input())
red = [[int(i) for i in input().split()] for j in range(n)]
blue = [[int(i) for i in input().split()] for j in range(n)]
red = sorted(red,key=max,reverse = True)
blue = sorted(blue,key=min,reverse=True)
usedRed= [False]*n 
usedBlue = [False]*n 
pairs = 0

for i,r in enumerate(red):
  for j,b in enumerate(blue):
    if usedRed[i] or usedBlue[j]:
      continue 
    if r[0]<b[0] and r[1]<b[1]:
      usedRed[i] = True 
      usedBlue[j] = True 
      pairs+=1
      
print(pairs)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = []
b = []
c = []
d = []
count = 0
for i in range(n):
    a_ad, b_ad = map(int, input().split())
    a.append(a_ad)
    b.append(b_ad)
for i in range(n):
    c_ad, d_ad = map(int, input().split())
    c.append(c_ad)
    d.append(d_ad)
wa = [a[i] + b[i] for i in range(n)]
wa_sort = sorted(wa, reverse = True)
sort_c = sorted(c)
for i in range(n):
    ind_a = wa.index(wa_sort[i])
    l = len(c)
    for k in range(l):
        ind_c = c.index(sort_c[k])
        if a[ind_a] < c[ind_c] and b[ind_a] < d[ind_c]:
            c = c[:ind_c] + c[ind_c+1:]
            d = d[:ind_c] + d[ind_c+1:]
            sort_c = sort_c[:k] + sort_c[k+1:]
            count += 1
            break
print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
ired = []
iblue = []

for i in range(n):
    a,b = map(int,input().split())
    ired.append([a,b])
    
for i in range(n):
    c,d = map(int,input().split())
    iblue.append([c,d])

red = sorted(ired)
blue = sorted(iblue)

x_ans = 0

for i in range(n):
    for j in range(n):
        if (blue[j][0] > red[i][0]) and (blue[j][1] > red[i][1]):
            blue[j] = [-1,-1]
            x_ans += 1
            break
        
red = sorted(ired,key = lambda x:x[1])
blue = sorted(iblue,key = lambda x:x[1])
y_ans = 0        
for i in range(n):
    for j in range(n):
        if (blue[j][0] > red[i][0]) and (blue[j][1] > red[i][1]):
            blue[j] = [-1,-1]
            y_ans += 1
            break        

 

print(max(x_ans,y_ans))

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    red = []
    for i in range(N):
        x,y = [int(i) for i in input().split()]
        red.append([x,y])
    blue = []
    for i in range(N):
        x,y = [int(i) for i in input().split()]
        blue.append([x,y])
    red.sort(reverse=True)
    blue.sort(reverse=True)
    #print(red)
    #print(blue)
    pair = 0
    for a in range(N):
        flag = False
        for i in range(N):
            for j in range(N):
                if(red[i][0] <= blue[j][0] and red[i][1] <= blue[j][1]):
                    pair = pair + 1
                    flag = True
                    #print(f'{red[i]} {blue[j]}')
                    blue[j][0] = -10000000000
                    blue[j][1] = -10000000000
                    break
                
        if flag:
            break
    print(pair)
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())

R = []
for i in range(N):
    x, y = list(map(int, input().split()))
    R.append((x, y))

B = []
for i in range(N):
    x, y = list(map(int, input().split()))
    B.append((x, y))

R.sort(key=lambda a:max(a[0],a[1]), reverse=True)
B.sort(key=lambda a:max(a[0],a[1]), reverse=True)

ans = 0
for pos in B:
    x, y = pos
    for pos2 in R:
        x2, y2 = pos2
        if x2<x and y2<y:
            R.remove(pos2)
            ans += 1
            break

print(ans)

Submission status: Wrong Answer

Solution code:
import copy

red=[]
blue=[]
ans1=0
ans2=0

N=int(input())
for i in range(N):
    a,b=map(int,input().split())
    red+=[[a,b]]
for i in range(N):
    c,d=map(int,input().split())
    blue+=[[c,d]]

red1,blue1=copy.deepcopy(red),copy.deepcopy(blue)
red2,blue2=copy.deepcopy(red),copy.deepcopy(blue)
red1.sort()
blue1.sort()
red2.sort(key=lambda x:x[1])
blue2.sort(key=lambda x:x[1])

for i in red1:
    for j in blue1:
        if i[0]<j[0]:
            if i[1]<j[1]:
                ans1+=1
                blue1.remove(j)
                break

for i in red2:
    for j in blue2:
        if i[1]<j[1]:
            if i[0]<j[0]:
                ans2+=1
                blue2.remove(j)
                break

ans=max(ans1,ans2)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
listRed = [[i for i in map(int,input().split())]for j in range(N)]
listBlue = [[i for i in map(int,input().split())]for j in range(N)]
ans = 0
sortRed = sorted(listRed,key = lambda x: x[0] + x[1])
sortBlue = sorted(listBlue,key = lambda x: x[0] + x[1])

for i in range(N):
    for j in range(len(sortBlue)):
        if sortRed[i][0] < sortBlue[j][0] and sortRed[i][1] < sortBlue[j][1]:
            ans += 1
            sortBlue.pop(j)
            break

print(ans)

Submission status: Wrong Answer

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

R = sorted(R)
R = list(reversed(R))
B = sorted(B)

res = 0
for r in R:
    mark = 0
    p = 0
    for i in range(len(B)):
        if r[0] < B[i][0]:
            mark = i
            p = 1
            break
    if p == 0:
        continue
        
    temp1 = B[mark:]
    temp2 = []
    
    for x, y in temp1:
        if y > r[1]:
            temp2.append(y)
    
    if len(temp2) > 0:
        j = temp2.index(min(temp2))
        B[mark+j][0], B[mark+j][1] = -1, -1
        res += 1
print(res)

Submission status: Wrong Answer

Solution code:
import copy

def main():
    N = int(input())
    abList = []
    cdList = []
    for i in range(N):
        [a, b] = list(map(int, input().split(' ')))
        abList.append( (a+b, a, b) )
    for i in range(N):
        [c, d] = list(map(int, input().split(' ')))
        cdList.append( (c+d, c, d) )
    abList.sort()
    cdList.sort()
    cdList2 = copy.copy( cdList )
    ans = 0
    for (_, a, b) in abList:
        for i in range( len(cdList) ):
            (_, c, d) = cdList[i]
            if a < c and b < d:
                cdList.pop(i)
                ans += 1
                break
    ans2 = 0
    abList.reverse()
    for (_, a, b) in abList:
        for i in range( len(cdList2) ):
            (_, c, d) = cdList2[i]
            if a < c and b < d:
                cdList2.pop(i)
                ans2 += 1
                break
    print( max(ans, ans2) )
main()

Submission status: Wrong Answer

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

R = sorted(R)
R = list(reversed(R))
B = sorted(B)

res = 0
for r in R:
    mark = 0
    p = 0
    for i in range(len(B)):
        if r[0] <= B[i][0]:
            mark = i
            p = 1
            break
    if p == 0:
        continue
        
    temp1 = B[mark:]
    temp2 = []
    
    for x, y in temp1:
        if y > r[1]:
            temp2.append(y)
    
    if len(temp2) > 0:
        j = temp2.index(min(temp2))
        B[mark+j][0], B[mark+j][1] = -1, -1
        res += 1
print(res)

Submission status: Wrong Answer

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

R = sorted(R)
R = list(reversed(R))
B = sorted(B)

res = 0
for r in R:
    mark = 0
    p = 0
    for i in range(len(B)):
        if r[0] <= B[i][0]:
            mark = i
            p = 1
            break
    if p == 0:
        continue
        
    temp1 = B[mark:]
    temp2 = []
    
    for x, y in temp1:
        if y >= r[1]:
            temp2.append(y)
    
    if len(temp2) > 0:
        j = temp2.index(min(temp2))
        B[mark+j][0], B[mark+j][1] = -1, -1
        res += 1
print(res)

Submission status: Wrong Answer

Solution code:
N = int(input())
red = [[int(j) for j in input().split()] for i in range(N)]
blue = [[int(j) for j in input().split()] for i in range(N)]

pair = 0

red.sort()
blue.sort()

for i in range(N):
    for j in range(len(red)):
        if red[j][0] > blue[i][0]:
            break
        elif red[j][1] < blue[i][1]:
            pair += 1
            red.pop(j)
            break

print(pair)

Submission status: Wrong Answer

Solution code:
n = int(input())

red = {}
for i in range(n):
    a, b = map(int, input().split())
    red[a] = b

blue = {}
for i in range(n):
    c, d = map(int, input().split())
    blue[c] = d

ans = 0

for bk, bv in blue.items():
    for rk in reversed(range(bk)):
        rv = red.get(rk)
        if rv is None:
            continue
        if rk < bk and rv < bv:
            red.pop(rk)
            ans += 1
            break

print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

N=int(input())
A=[]
B=[]
T=[]
for i in range(N):
    a,b=map(int, input().split())
    A.append(a)
    B.append(b)
    T.append(max(a,b))
C=[]
D=[]
S=[]
for i in range(N):
    c,d=map(int, input().split())
    C.append(c)
    D.append(d)
    S.append(min(c,d))

Ts=sorted(T,reverse=True)
Ss=sorted(S)

p=0
for i in Ts:
    for j in Ss:
        if A[T.index(i)]<C[S.index(j)] and B[T.index(i)]<D[S.index(j)]:
            p+=1
            Ss.remove(j)
            break

print(p)

Submission status: Wrong Answer

Solution code:
N = int(input())
listRed = [[i for i in map(int,input().split())]for j in range(N)]
listBlue = [[i for i in map(int,input().split())]for j in range(N)]
ans = 0
sortRed = sorted(listRed,key = lambda x: x[0] + x[1],reverse=True)
sortBlue = sorted(listBlue,key = lambda x: x[0] + x[1],reverse=True)

for i in range(N):
    for j in range(len(sortBlue)):
        if sortRed[i][0] < sortBlue[j][0] and sortRed[i][1] < sortBlue[j][1]:
            ans += 1
            sortBlue.pop(j)
            break

print(ans)

Submission status: Wrong Answer

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


def solve(AB, CD):
    AB_set = []
    CD_set = []
    for index_ab, ab in enumerate(AB):
        i, j = -1, -1
        if index_ab in AB_set:
            continue
        distance = float('inf')
        for index_cd, cd in enumerate(CD):
            if index_cd in CD_set:
                continue
            if (cd[0] - ab[0] >= 0) & (cd[1] - ab[1] >= 0) & ((cd[0]-ab[0]) + (cd[1] - ab[1]) <= distance):
                distance = (cd[0] - ab[0]) + (cd[1] - ab[1])
                i, j = index_ab, index_cd
        if (i != -1) & (j != -1):
            AB_set.append(i)
            CD_set.append(j)
    return len(AB_set)

AB.sort()
CD.sort()
ans1 = solve(AB, CD)
AB.sort(reverse=True)
CD.sort(reverse=True)
ans2 = solve(AB, CD)
AB.sort(key=lambda x:x[1])
CD.sort(key=lambda x:x[1])
ans3 = solve(AB, CD)
AB.sort(key=lambda x:x[1], reverse=True)
CD.sort(key=lambda x:x[1], reverse=True)
ans4 = solve(AB, CD)
AB.sort()
CD.sort(key=lambda x:x[1])
ans5 = solve(AB, CD)
AB.sort(reverse=True)
CD.sort(key=lambda x:x[1], reverse=True)
ans6 = solve(AB, CD)
AB.sort(key=lambda x:x[1])
CD.sort()
ans7 = solve(AB, CD)
AB.sort(key=lambda x:x[1], reverse=True)
CD.sort(reverse=True)
ans8 = solve(AB, CD)
print(max(ans1, ans2, ans3, ans4, ans5, ans6, ans7, ans8))

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    red = []
    for i in range(N):
        x,y = [int(i) for i in input().split()]
        red.append([x,y])
    blue = []
    for i in range(N):
        x,y = [int(i) for i in input().split()]
        blue.append([x,y])
    red.sort(reverse=True)
    blue.sort(reverse=True)
    #print(red)
    #print(blue)
    pair = 0
    for a in range(N):
        flag = False
        for i in range(N):
            for j in range(N):
                if(red[i][0] <= blue[j][0] and red[i][1] <= blue[j][1]):
                    pair = pair + 1
                    flag = True
                    #print(f'{red[i]} {blue[j]}')
                    blue[j][0] = -10000
                    break
                
        if flag:
            break
    print(pair)
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# -- coding: utf-8 --
N = int(input())
red = []
for i in range(N):
    red.append(list(map(int, input().split(' '))))
blue = []
for i in range(N):
    blue.append(list(map(int, input().split(' '))))
mred = sorted(red)
mblue = sorted(blue, reverse=True)
count = 0
minsum = 100000
cand = 1000000
for i in range(N):
    last = mred.pop()
    for num, l in enumerate(mblue[:]):
        tmpsum = sum(l)
        if last[0] < l[0] and last[1] < l[1] and min(minsum, tmpsum) == tmpsum:
            cand = num
            minsum = tmpsum

    if cand < len(mblue):
        count += 1
        mblue.pop(cand)
    cand = 1000000
    minsum = 1000000

print(count)

Submission status: Wrong Answer

Solution code:
n=int(input())
ab=[]
for _ in range(n):
    ax=list((map(int,input().split())))
    ax.extend([False])
    ab.append(ax)
cd=[]
for _ in range(n):
    cx=list(map(int,input().split()))
    cx.extend([False])
    cd.append(cx)
ans=0
sba=sorted(ab,key=lambda x:x[0]**2+x[1]**2,reverse=True)
scd=sorted(cd,key=lambda x:x[0]**2+x[1]**2,reverse=True)
for c in scd:
    for a in sba:
        if a[0]<c[0] and a[1]<c[1] and a[2]==False:
            ans+=1
            a[2]=True
            break
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
red_list = []
x_min = 200
for i in range(n):
    x, y = map(int, input().split())
    x_min = min(x_min, x)
    red_list.append((x, y))
red_list = sorted(red_list)
blue_list = []
for i in range(n):
    x, y = map(int, input().split())
    if x_min < x:
        blue_list.append((x, y))
blue_list = sorted(blue_list, key=lambda x: x[1])

max_pair = min(len(red_list), len(blue_list))
pair = 0
for blue in blue_list:
    flag = 0
    p_x, p_y = 200, 200
    for red in red_list:
        if blue[0] > red[0] and blue[1] > red[1]:
            if min(p_x, p_y) > min((blue[0]-red[0]), (blue[1]-red[1])):
                p_x = red[0]
                p_y = red[1]
                flag = 1
    if flag == 1:
        pair += 1
        red_list.remove((p_x, p_y))
    if pair >= max_pair:
        break

print(pair)

Submission status: Wrong Answer

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


def solve(AB, CD):
    AB_set = []
    CD_set = []
    for index_ab, ab in enumerate(AB):
        i, j = -1, -1
        if index_ab in AB_set:
            continue
        distance = float('inf')
        for index_cd, cd in enumerate(CD):
            if index_cd in CD_set:
                continue
            if (cd[0] - ab[0] >= 0) & (cd[1] - ab[1] >= 0) & ((cd[0]-ab[0]) + (cd[1] - ab[1]) < distance):
                distance = (cd[0] - ab[0]) + (cd[1] - ab[1])
                i, j = index_ab, index_cd
        if (i != -1) & (j != -1):
            AB_set.append(i)
            CD_set.append(j)
    return len(AB_set)

AB.sort()
CD.sort()
ans1 = solve(AB, CD)
AB.sort(reverse=True)
CD.sort(reverse=True)
ans2 = solve(AB, CD)
AB.sort(key=lambda x:x[1])
CD.sort(key=lambda x:x[1])
ans3 = solve(AB, CD)
AB.sort(key=lambda x:x[1], reverse=True)
CD.sort(key=lambda x:x[1], reverse=True)
ans4 = solve(AB, CD)
AB.sort()
CD.sort(key=lambda x:x[1])
ans5 = solve(AB, CD)
AB.sort(reverse=True)
CD.sort(key=lambda x:x[1], reverse=True)
ans6 = solve(AB, CD)
AB.sort(key=lambda x:x[1])
CD.sort()
ans7 = solve(AB, CD)
AB.sort(key=lambda x:x[1], reverse=True)
CD.sort(reverse=True)
ans8 = solve(AB, CD)
print(max(ans1, ans2, ans3, ans4, ans5, ans6, ans7, ans8))

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    red = []
    for i in range(N):
        x,y = [int(i) for i in input().split()]
        red.append([x,y])
    blue = []
    for i in range(N):
        x,y = [int(i) for i in input().split()]
        blue.append([x,y])
    red.sort(reverse=True)
    blue.sort(reverse=True)
    #print(red)
    #print(blue)
    pair = 0
    for a in range(N):
        flag = False
        for i in range(N):
            for j in range(N):
                if(red[i][0] < blue[j][0] and red[i][1] < blue[j][1]):
                    pair = pair + 1
                    flag = True
                    #print(f'{red[i]} {blue[j]}')
                    blue[j][0] = -10000
                    break
                
        if flag:
            break
    print(pair)
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
    N = int(input().strip())
    lines = [input().split() for _ in range(N)]
    a_b = [(int(line[0]), int(line[1])) for line in lines]
    lines = [input().split() for _ in range(N)]
    c_d = [(int(line[0]), int(line[1])) for line in lines]

    a_b = sorted(a_b, key=lambda e: min(e[0], e[1]))
    c_d = sorted(c_d, key=lambda e: min(e[0], e[1]))

    count = 0
    for i, (a, b) in enumerate(a_b):
        c_d_index = None
        for j, (c, d) in enumerate(c_d):
            if a < c and b < d:
                # print("(a, b), (c, d): ({}, {}), ({}, {})".format(a, b, c, d))
                count += 1
                c_d.pop(j)
                break

    print(count)

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    red = []
    for i in range(N):
        x,y = [int(i) for i in input().split()]
        red.append([x,y])
    blue = []
    for i in range(N):
        x,y = [int(i) for i in input().split()]
        blue.append([x,y])
    red.sort(reverse=True)
    blue.sort(reverse=True)
    print(red)
    print(blue)
    pair = 0
    for a in range(N):
        flag = False
        for i in range(N):
            for j in range(N):
                if(red[i][0] < blue[j][0] and red[i][1] < blue[j][1]):
                    pair = pair + 1
                    flag = True
                    #print(f'{red[i]} {blue[j]}')
                    blue[j][0] = -10000
                    break
                
        if flag:
            break
    print(pair)
if __name__ == '__main__':
    main()