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:
N = int(input())
AB = [list(map(int, input().split())) for _ in range(N)]
CD = [list(map(int, input().split())) for _ in range(N)]

AB.sort(key = lambda x: -x[1])
AB.sort(key = lambda x: -x[0])
CD.sort(key = lambda x: -x[1])
CD.sort(key = lambda x: -x[0])

check = [1] * N
answer = 0

for a, b in AB:
  for i in range(N):
    c, d = CD[i][0], CD[i][1]
    #print("a, b, c, d:", a, b, c, d)
    if c > a and d > b and check[i]:
      check[i] = 0
      answer += 1
      break
print(answer)

Submission status: Wrong Answer

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

AB.sort()
CD.sort()
AB = AB[::-1]
CD = CD[::-1]

check = [1] * N
answer = 0

for a, b in AB:
  for i in range(N):
    c, d = CD[i][0], CD[i][1]
    #print("a, b, c, d:", a, b, c, d)
    if c > a and d > b and check[i]:
      check[i] = 0
      answer += 1
      break
print(answer)

Submission status: Wrong Answer

Solution code:
N = int(input())
ab = [0] * N
cd = [0] * N
for i in range(N):
  ab[i] = list(map(int, input().split())) + [i]
for i in range(N):
  cd[i] = list(map(int, input().split()))
#print(ab)
#print(cd)

pair = [0] * N
friend = [[] for _ in range(N)]

for i in range(N):
  for j in range(N):
    if ab[i][0] < cd[j][0] and ab[i][1] < cd[j][1]:
      friend[j].append(ab[i])
#print("friend:", friend)

order = [[len(friend[i]), i] for i in range(N)]
order.sort()
#print("order:", order)

answer = 0
for i in order:
  if i[0] == 0:
    continue
  i = i[1]
  for f in friend[i]:
    if pair[f[2]] == 0:
      pair[f[2]] = 1
      answer += 1
      break
print(answer)

Submission status: Wrong Answer

Solution code:
n = int(input())
red = sorted([tuple(map(int, input().split())) for _ in range(n)]) + [(2*n, 2*n)]
blue = sorted([tuple(map(int, input().split())) for _ in range(n)])

res = 0
for bx, by in blue:
    tmp = 0
    for r in range(len(red) - 1):
        if red[tmp][1] <= red[r][1] < by:
            tmp = r
        r1x, r1y = red[r]
        r2x, r2y = red[r + 1]
        if r1x < bx and r1y < by and (bx <= r2x or by <= r2y):
            res += 1
            red.pop(tmp)
            break

print(res)

Submission status: Wrong Answer

Solution code:
n = int(input())
red = sorted([tuple(map(int, input().split())) for _ in range(n)]) + [(2*n, 2*n)]
blue = sorted([tuple(map(int, input().split())) for _ in range(n)])

res = 0
for bx, by in blue:
    tmp = 0
    for r in range(len(red) - 1):
        if red[r][1] >= red[tmp][1]:
            tmp = r
        r1x, r1y = red[r]
        r2x, r2y = red[r + 1]
        if r1x < bx and r1y < by and (bx <= r2x or by <= r2y):
            res += 1
            red.pop(tmp)
            break

print(res)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter
n = int(input())
red = [tuple(map(int, input().split())) for _ in range(n)]
blue = [tuple(map(int, input().split())) for _ in range(n)]
red.sort()
blue.sort(key=itemgetter(1))
blue_flag = [False] * n
for i in range(n):
    pair_blue_index = float('inf')
    for j in range(n):
        if not (blue_flag[j]) and red[i][0] < blue[j][0] and red[i][1] < blue[j][1]:
            pair_blue_index = j
            break
    if pair_blue_index != float('inf'):
        blue_flag[pair_blue_index] = True
print(blue_flag.count(True))

Submission status: Wrong Answer

Solution code:
n = int(input())
red = [tuple(map(int, input().split())) for _ in range(n)]
blue = [tuple(map(int, input().split())) for _ in range(n)]
red.sort()
blue.sort()
blue_flag = [False] * n
for i in range(n):
    pair_blue_index = float('inf')
    for j in range(n):
        if not (blue_flag[j]) and red[i][0] < blue[j][0] and red[i][1] < blue[j][1]:
            if pair_blue_index == float('inf') or blue[pair_blue_index][1] > blue[j][1]:
                pair_blue_index = j
    if pair_blue_index != float('inf'):
        blue_flag[pair_blue_index] = True
print(blue_flag.count(True))

Submission status: Wrong Answer

Solution code:
n = int(input())
red = [tuple(map(int, input().split())) for _ in range(n)]
blue = [tuple(map(int, input().split())) for _ in range(n)]
red.sort()
blue.sort()
blue_flag = [False] * n
for i in range(n):
    pair_blue_index = float('inf')
    for j in range(n):
        if not (blue_flag[j]) and red[i][0] < blue[j][0] and red[i][1] < blue[j][1]:
            if pair_blue_index == float('inf'):
                pair_blue_index = j
            else:
                now_diff = abs(blue[pair_blue_index][1] - red[i][1])
                if now_diff > abs(blue[j][1] - red[i][1]):
                    pair_blue_index = j
    if pair_blue_index != float('inf'):
        blue_flag[pair_blue_index] = True
print(blue_flag.count(True))

Submission status: Wrong Answer

Solution code:
n = int(input())
reds = [tuple(map(int, input().split())) for _ in range(n)]
blues = [tuple(map(int, input().split())) for _ in range(n)]

pairs = 0
for blue in blues:
    red_max_y = -float("inf")
    arg_max = -1
    for idx, red in enumerate(reds):
        if red[0] < blue[0] and red[1] < blue[1]:
            if red[1] > red_max_y:
                red_max_y = red[1]
                arg_max = idx
    if arg_max != -1:
        del reds[arg_max]
        pairs += 1

print(pairs)

Submission status: Wrong Answer

Solution code:
N = int(input())
reds = sorted([tuple(map(int, input().split())) for _ in range(N)], reverse=True)
blues = sorted([tuple(map(int, input().split())) for _ in range(N)], reverse=True)
ans = 0
for b in blues:
    for r in reds:
        if r[0] < b[0] and r[1] < b[1]:
            ans += 1
            reds.remove(r)
            break
print(ans)

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())
    AB=[list(map(int,input().split())) for _ in range(n)]
    CD=[list(map(int,input().split())) for _ in range(n)]
    AB.sort()
    CD.sort(lambda x:x[1])

    ans=0
    for i in range(n):
        a,b=AB[i]
        for j in range(n):
            c,d=CD[j]
            if(a<c and b<d):
                AB[i]=[INF,INF]
                CD[j]=[-INF,-INF]
                ans+=1
                break
    print(ans)
resolve()

Submission status: Wrong Answer

Solution code:



N = int(input())

r = []
for _ in range(N):
    x,y = map(int, input().split())
    r.append((-y,x))

b = []
for _ in range(N):
    x,y = map(int, input().split())
    b.append((y,x))

r.sort()
b.sort()

ans = 0
for my,x in r:
    for j in range(len(b)):
        if  -my < b[j][0] and x < b[j][1]:
            ans += 1
            b.pop(j)
            break

print(ans)

Submission status: Wrong Answer

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

for i in range(N-1):
    for k in range(N - 1, i, -1):
        if min(ab[k]) > min(ab[k-1]):
            tmp = ab[k]
            ab[k] = ab[k-1]
            ab[k-1] = tmp

for i in range(N-1):
    for k in range(N - 1, i, -1):
        if min(cd[k]) > min(cd[k-1]):
            tmp = cd[k]
            cd[k] = cd[k-1]
            cd[k-1] = tmp
'''
print("a, b")
print(ab)
print("c, d")
print(cd)
'''
ans = 0

for i in range(N):
    red_x, red_y = ab[i][0], ab[i][1]
    for k in range(len(cd)):
        blue_x, blue_y = cd[k][0], cd[k][1]
        if red_x < blue_x and red_y < blue_y:
            ans += 1
            del cd[k]
            break

print(ans)

Submission status: Wrong Answer

Solution code:
# ABC091C
# 方針：x, y座標が最小値の点をとっていく
N = int(input())
ab = [list(map(int, input().split())) for _ in range(N)]
cd = [list(map(int, input().split())) for _ in range(N)]

for i in range(N-1):
    for k in range(N - 1, i, -1):
        if min(ab[k]) < min(ab[k-1]):
            tmp = ab[k]
            ab[k] = ab[k-1]
            ab[k-1] = tmp

for i in range(N-1):
    for k in range(N - 1, i, -1):
        if min(cd[k]) < min(cd[k-1]):
            tmp = cd[k]
            cd[k] = cd[k-1]
            cd[k-1] = tmp

ans = 0

for i in range(N):
    red_x, red_y = ab[i][0], ab[i][1]
    for k in range(len(cd)):
        blue_x, blue_y = cd[k][0], cd[k][1]
        if red_x < blue_x and red_y < blue_y:
            ans += 1
            del cd[k]
            break

print(ans)

Submission status: Wrong Answer

Solution code:
# ABC091C
# 方針：x, y座標が最小値の点をとっていく
N = int(input())
ab = [list(map(int, input().split())) for _ in range(N)]
cd = [list(map(int, input().split())) for _ in range(N)]

for i in range(0, N-1):
    for k in range(1, N - i):
        if min(ab[k]) < min(ab[k-1]):
            tmp = ab[k]
            ab[k] = ab[k-1]
            ab[k-1] = tmp

for i in range(N-1):
    for k in range(1, N - i):
        if min(cd[k]) < min(cd[k-1]):
            tmp = cd[k]
            cd[k] = cd[k-1]
            cd[k-1] = tmp

ans = 0

for i in range(N):
    red_x, red_y = ab[i][0], ab[i][1]
    for k in range(len(cd)):
        blue_x, blue_y = cd[k][0], cd[k][1]
        if red_x < blue_x and red_y < blue_y:
            ans += 1
            del cd[k]
            break

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
red = []
blue = []
for _ in range(N):
    a , b = map(int,input().split())
    red.append([(a ** 2 + b ** 2) ** (1 / 2),a , b ])
    #red.append([a, b])
for _ in range(N):
    a, b = map(int, input().split())
    blue.append([(a ** 2 + b ** 2) ** (1 / 2),a , b ])
    #blue.append([a, b])

red.sort(reverse=True)
#red.sort(reverse=True , key= lambda x: x[1])
blue.sort()
#blue.sort(key= lambda x: x[1])
find = []
#print(red)
#print(blue)
for i in range(N):
    for j in range(N-1 , -1 ,-1):
        #print(red[i][1])
        #print(blue[j][1])
        if red[i][1] < blue[j][1] and red[i][2] < blue[j][2] and not blue[j] in find:
        #if red[i][1] < blue[j][1] and red[i][0] < blue[j][0] and not blue[j] in find:
            find.append(blue[j])
            break
#print(find)
print(len(find))

Submission status: Wrong Answer

Solution code:
N = int(input())
red = []
blue = []
for _ in range(N):
    a , b = map(int,input().split())
    #red.append([(a ** 2 + b ** 2) ** (1 / 2),a , b ])
    red.append([a, b])
for _ in range(N):
    a, b = map(int, input().split())
    #blue.append([(a ** 2 + b ** 2) ** (1 / 2),a , b ])
    blue.append([a, b])
red.sort(reverse=True)
red.sort(reverse=True , key= lambda x: x[1])
blue.sort()
blue.sort(key= lambda x: x[1])
find = []
#print(red)
#print(blue)
for i in range(N):
    for j in range(N-1 , -1 ,-1):
        #print(red[i][1])
        #print(blue[j][1])
        if red[i][1] < blue[j][1] and red[i][0] < blue[j][0] and not blue[j] in find:
            find.append(blue[j])
            break
#print(find)
print(len(find))

Submission status: Wrong Answer

Solution code:
import sys
if sys.platform =='ios':
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def MAP(): return [int(s) for s in input().split()]

N = int(input())
A = [[False,MAP()] for _ in range(N)]
B = [[False,MAP()] for _ in range(N)]

A = sorted(A, key=lambda x:-x[1][1])
B = sorted(B, key=lambda x:x[1])

#after reading answer
count = 0
for b in B:
	cand = []
	for a in A:
		if b[1][0] > a[1][0] and b[1][1] > a[1][1] and not a[0]:
			b[0] = True
			a[0] = True
			count += 1

print(count)

Submission status: Wrong Answer

Solution code:
import sys
if sys.platform =='ios':
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def MAP(): return [int(s) for s in input().split()]

N = int(input())
A = [[False,MAP()] for _ in range(N)]
B = [[False,MAP()] for _ in range(N)]

A = sorted(A, key=lambda x:x[1] * -1)
B = sorted(B, key=lambda x:x[1])

#after reading answer
count = 0
for b in B:
	cand = []
	for a in A:
		if b[1][0] > a[1][0] and b[1][1] > a[1][1] and not a[0]:
			b[0] = True
			a[0] = True
			count += 1

print(count)

Submission status: Wrong Answer

Solution code:
import sys
import copy
if sys.platform =='ios':
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def MAP(): return [int(s) for s in input().split()]

N = int(input())
A = [[False,MAP()] for _ in range(N)]
B = [[False,MAP()] for _ in range(N)]

#after reading answer
count = 0
for b in B:
	cand = []
	for a in A:
		if b[1][0] > a[1][0] and b[1][1] > a[1][1] and not a[0]:
			cand.append(a)
	cand = sorted(cand, key=lambda x:x[1][1], reverse=True)
	if cand:
		#print(b, cand[0])
		b[0] = True
		cand[0][0] = True
		count += 1

print(count)

Submission status: Wrong Answer

Solution code:
import sys
import copy
if sys.platform =='ios':
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def MAP(): return [int(s) for s in input().split()]

N = int(input())
A = [[False,MAP()] for _ in range(N)]
B = [[False,MAP()] for _ in range(N)]

#print(sorted(B))

#below is wrong 
#count = 0
#for b in B:
#	delta = []
#	for a in A:
#		delta.append([a,[b[1][0] - a[1][0], b[1][1] - a[1][1]]])
	#print(b,delta)
#	cand = [[d[1][0]+d[1][1],d[0][1]] for d in delta if not d[0][0] and d[1][0] > 0 and d[1][1] > 0]
#	if cand:
#		cand = sorted(cand)
#		print(cand)
#		b[0] = True
#		A[A.index([False,cand[0][1]])][0] = True
#		count += 1

#after reading answer
count = 0
for b in B:
	cand = []
	for a in A:
		if b[1][0] > a[1][0] and not a[0]:
			cand.append(a)
	cand = sorted(cand, key=lambda x:x[1][1], reverse=True)
	if cand:
		#print(b, cand[0])
		b[0] = True
		cand[0][0] = True
		count += 1

print(count)

Submission status: Wrong Answer

Solution code:
import sys
import copy
if sys.platform =='ios':
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def MAP(): return [int(s) for s in input().split()]

N = int(input())
A = [[False,MAP()] for _ in range(N)]
B = [[False,MAP()] for _ in range(N)]

#print(sorted(B))

count = 0
for b in B:
	delta = []
	for a in A:
		delta.append([a,[b[1][0] - a[1][0], b[1][1] - a[1][1]]])
	#print(b,delta)
	cand = [[d[1][0]+d[1][1],d[0][1]] for d in delta if not d[0][0] and d[1][0] > 0 and d[1][1] > 0]
	if cand:
		cand = sorted(cand)
		#print(cand)
		b[0] = True
		A[A.index([False,cand[0][1]])][0] = True
		count += 1
			
print(count)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[]
for i in range(n):
    a.append(list(map(int,input().split())))
b=[]
for i in range(n):
    b.append(list(map(int,input().split())))
a.sort()
b=sorted(b,key=lambda x: x[0])
ans=0
vb=[]
for i in range(n):
    for j in range(n):
        if not j in vb:
            if a[i][0]<b[j][0] and a[i][1]<b[j][1]:
                vb.append(j)
                ans+=1
                break
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import copy
if sys.platform =='ios':
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def MAP(): return [int(s) for s in input().split()]

N = int(input())
A = [[0,MAP()] for _ in range(N)]
B = [[0,MAP()] for _ in range(N)]

#print(sorted(B))

fA = copy.deepcopy(A)
fB = copy.deepcopy(B)
fA = sorted(fA, key=lambda x:x[1][0])
fB = sorted(fB, key=lambda x:x[1][0])

fcount = 0
for b in fB:
	for a in fA:
		if b[0] == 1 or a[0] == 1:
			continue
		if b[1][0] > a[1][0] and b[1][1] > a[1][1]:
			#print(b[1],'---',a[1])
			fcount += 1
			b[0] = 1
			a[0] = 1

#print(A, B)
sA = copy.deepcopy(A)
sB = copy.deepcopy(B)
# sort on second value
sA = sorted(sA, key=lambda x:x[1][1])
sB = sorted(sB, key=lambda x:x[1][1])

scount = 0
for b in sB:
	for a in sA:
		if b[0] == 1 or a[0] == 1:
			continue
		if b[1][0] > a[1][0] and b[1][1] > a[1][1]:
			#print(b[1],'---',a[1])
			scount += 1
			b[0] = 1
			a[0] = 1
			
print(max(fcount,scount))

Submission status: Wrong Answer

Solution code:
#091c
from collections import deque

N = int(input())

red_point_list = []
blue_point_list = deque()

for i in range(N):
    a,b = map(int, input().split())
    red_point_list.append((a,b))
for i in range(N):
    c,d = map(int, input().split())
    blue_point_list.append((c,d))

#すべての組み合わせ　#100! = 9 * 10**157　∴地球爆発

#原点から近いところにある赤い点を選択。pair選択済みでない、かつ、pairになる青い点のうち最も近いものを選択 ……NG
    #red :(1,1),(2,2)
    #blue:(3,3),(2,100)
    #(1,1)-(2,100),(2,2)-(3,3)で2が答えだが、近い点から選んでいると1になってしまう


#全ての青い点に対して、カバーできる赤い点を計算　100*100
available_pair_dict = dict() #keyが青い点の座標、valueがペアになりうる赤い点の座標のリスト
available_pair_count_dict = dict() #keyが青い点の座標、valueがペアになりうる赤い点の個数

for blue_point in blue_point_list:
  blue_point_x = blue_point[0]
  blue_point_y = blue_point[1]

  available_pair = []

  for red_point in red_point_list:
    red_point_x = red_point[0]
    red_point_y = red_point[1]
    if red_point_x < blue_point_x and red_point_y < blue_point_y:
      available_pair.append((red_point))

  available_pair_dict[blue_point] = available_pair
  available_pair_count_dict[blue_point] = len(available_pair)

#カバーできる赤い点が少ない方から多くなるように並び替え
available_pair_count_dict_sorted = sorted(available_pair_count_dict.items(), key=lambda x:x[1])
#カバーできる赤い点が少ない青い点からペアを決めていく
used_red_point = set()
ans = 0

for blue_point in available_pair_count_dict_sorted:
  #print(blue_point[0],available_pair_dict[blue_point[0]])
  available_pair = set(available_pair_dict[blue_point[0]])
  available_pair = available_pair - used_red_point
  if len(available_pair) != 0:
    paired = available_pair.pop()
    used_red_point.add(paired)
    ans += 1
    #print("blue",blue_point[0],"red",paired)

print(ans)

Submission status: Wrong Answer

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

b_f = [-1] * n
r_f = [-1] * n

pair = []
count = 0
for i in range(n):
    if b_f[i] == -1:
        tmp = []
        for j in range(n):
            if b[i][0] > r[j][0] and b[i][1] > r[j][1] and r_f[j] == -1:
                tmp.append(j)
            
        if len(tmp) != 0:     
            pair_j = max(tmp, key=lambda j: b[j][1])
            count += 1
            b_f[i] = 1
            r_f[pair_j] = 1
print(count)

Submission status: Wrong Answer

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

b_f = [-1] * n
r_f = [-1] * n

pair = []
count = 0
for i in range(n):
    if b_f[i] == -1:
        tmp = []
        for j in range(n):
            if b[i][0] > r[j][0] and b[i][1] > r[j][1] and b_f[j] == -1:
                tmp.append(j)
            
        if len(tmp) != 0:     
            pair_j = max(tmp, key=lambda j: b[j][1])
            count += 1
            b_f[i] = 1
            r_f[pair_j] = 1
print(count)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[]
for i in range(n):
    a.append(list(map(int,input().split())))
b=[]
for i in range(n):
    b.append(list(map(int,input().split())))
a.sort()
b=sorted(b,key=lambda x: x[1])
ans=0
vb=[]
for i in range(n):
    for j in range(n):
        if not j in vb:
            if a[i][0]<b[j][0] and a[i][1]<b[j][1]:
                vb.append(j)
                ans+=1
                break
print(ans)

Submission status: Wrong Answer

Solution code:
#最大二部マッチング
def dfs(v, edges, n):
    visited = set()
    matched = [-1] * n
    for u in edges[v]:
        if u in visited:
            continue
        visited.add(u)
        if matched[u] == -1 or dfs(matched[u], visited):
            matched[u] = v
            return True
    return False
def examC():
    N = I()
    ab = [LI() for _ in range(N)]
    cd = [LI() for _ in range(N)]
    xn = N; yn = N
    E = [set() for _ in range(xn)]
    for i in range(xn):
        for j in range(yn):
            if ab[i][0]<cd[j][0] and ab[i][1]<cd[j][1]:
                E[i].add(j)
    ans = 0
    for s in range(xn):
        ans += dfs(s, E, yn)
    print(ans)

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 S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examC()

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[]
for i in range(n):
    a.append(list(map(int,input().split())))
b=[]
for i in range(n):
    b.append(list(map(int,input().split())))
a.sort()
b=sorted(b,key=lambda x: -x[1])
ans=0
vb=[]
for i in range(n):
    for j in range(n):
        if not j in vb:
            if a[i][0]<b[j][0] and a[i][1]<b[j][1]:
                vb.append(j)
                ans+=1
                break
print(ans)

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())
    ABorg=[tuple(map(int,input().split())) for _ in range(n)]
    CDorg=[tuple(map(int,input().split())) for _ in range(n)]
    ans=0

    # a,bの昇順にマッチング
    AB=ABorg[:]
    CD=CDorg[:]
    AB.sort()
    CD.sort()
    score=0
    for i in range(n):
        a,b=AB[i]
        for j in range(n):
            c,d=CD[j]
            if(a<c and b<d):
                score+=1
                CD[j]=(-1,-1)
                break
    ans=max(ans,score)

    # a,bの降順にマッチング
    AB=ABorg[:]
    CD=CDorg[:]
    AB.sort(reverse=1)
    CD.sort()
    score=0
    for i in range(n):
        a,b=AB[i]
        for j in range(n):
            c,d=CD[j]
            if(a<c and b<d):
                score+=1
                CD[j]=(-1,-1)
                break
    ans=max(ans,score)

    # c,dの昇順にマッチング
    AB=ABorg[:]
    CD=CDorg[:]
    AB.sort()
    CD.sort()
    score=0
    for i in range(n):
        c,d=CD[i]
        for j in range(n):
            a,b=AB[j]
            if(a<c and b<d):
                score+=1
                AB[j]=(INF,INF)
                break
    ans=max(ans,score)

    # c,dの降順にマッチング
    AB=ABorg[:]
    CD=CDorg[:]
    AB.sort()
    CD.sort(reverse=1)
    score=0
    for i in range(n):
        c,d=CD[i]
        for j in range(n):
            a,b=AB[j]
            if(a<c and b<d):
                score+=1
                AB[j]=(INF,INF)
                break
    ans=max(ans,score)

    ABI=[0]*n
    CDI=[0]*n
    for i in range(n):
        a,b=ABorg[i]
        ABI[i]=(a,b,0)
        c,d=CDorg[i]
        CDI[i]=(c,d,1)
    X=ABI+CDI
    X.sort(lambda x:x[0]+x[1])

    # print(X)
    score=0
    for i in range(2*n):
        if(X[i][2]==0): continue
        c,d=X[i][0],X[i][1]
        for j in range(i-1,-1,-1):
            if(X[j][2]==1): continue
            a,b=X[j][0],X[j][1]
            if(a<c and b<d):
                score+=1
                X[j]=(INF,INF,INF)
                break
    ans=max(ans,score)

    ABI=[0]*n
    CDI=[0]*n
    for i in range(n):
        a,b=ABorg[i]
        ABI[i]=(a,b,0)
        c,d=CDorg[i]
        CDI[i]=(c,d,1)
    X=ABI+CDI
    X.sort(lambda x:min(x[0],x[1]))

    # print(X)
    score=0
    for i in range(2*n):
        if(X[i][2]==0): continue
        c,d=X[i][0],X[i][1]
        for j in range(i-1,-1,-1):
            if(X[j][2]==1): continue
            a,b=X[j][0],X[j][1]
            if(a<c and b<d):
                score+=1
                X[j]=(INF,INF,INF)
                break
    ans=max(ans,score)

    ABI=[0]*n
    CDI=[0]*n
    for i in range(n):
        a,b=ABorg[i]
        ABI[i]=(a,b,0)
        c,d=CDorg[i]
        CDI[i]=(c,d,1)
    X=ABI+CDI
    X.sort(lambda x:max(x[0],x[1]))

    # print(X)
    score=0
    for i in range(2*n):
        if(X[i][2]==0): continue
        c,d=X[i][0],X[i][1]
        for j in range(i-1,-1,-1):
            if(X[j][2]==1): continue
            a,b=X[j][0],X[j][1]
            if(a<c and b<d):
                score+=1
                X[j]=(INF,INF,INF)
                break
    ans=max(ans,score)

    ABI=[0]*n
    CDI=[0]*n
    for i in range(n):
        a,b=ABorg[i]
        ABI[i]=(a,b,0)
        c,d=CDorg[i]
        CDI[i]=(c,d,1)
    X=ABI+CDI
    X.sort(lambda x:abs(x[0]-x[1]))

    # print(X)
    score=0
    for i in range(2*n):
        if(X[i][2]==0): continue
        c,d=X[i][0],X[i][1]
        for j in range(i-1,-1,-1):
            if(X[j][2]==1): continue
            a,b=X[j][0],X[j][1]
            if(a<c and b<d):
                score+=1
                X[j]=(INF,INF,INF)
                break
    ans=max(ans,score)

    print(ans)
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())
    ABorg=[tuple(map(int,input().split())) for _ in range(n)]
    CDorg=[tuple(map(int,input().split())) for _ in range(n)]
    ans=0

    # a,bの昇順にマッチング
    AB=ABorg[:]
    CD=CDorg[:]
    AB.sort()
    CD.sort()
    score=0
    for i in range(n):
        a,b=AB[i]
        for j in range(n):
            c,d=CD[j]
            if(a<c and b<d):
                score+=1
                CD[j]=(-1,-1)
                break
    ans=max(ans,score)

    # a,bの降順にマッチング
    AB=ABorg[:]
    CD=CDorg[:]
    AB.sort(reverse=1)
    CD.sort()
    score=0
    for i in range(n):
        a,b=AB[i]
        for j in range(n):
            c,d=CD[j]
            if(a<c and b<d):
                score+=1
                CD[j]=(-1,-1)
                break
    ans=max(ans,score)

    # c,dの昇順にマッチング
    AB=ABorg[:]
    CD=CDorg[:]
    AB.sort()
    CD.sort()
    score=0
    for i in range(n):
        c,d=CD[i]
        for j in range(n):
            a,b=AB[j]
            if(a<c and b<d):
                score+=1
                AB[j]=(INF,INF)
                break
    ans=max(ans,score)

    # c,dの降順にマッチング
    AB=ABorg[:]
    CD=CDorg[:]
    AB.sort()
    CD.sort(reverse=1)
    score=0
    for i in range(n):
        c,d=CD[i]
        for j in range(n):
            a,b=AB[j]
            if(a<c and b<d):
                score+=1
                AB[j]=(INF,INF)
                break
    ans=max(ans,score)

    # sort を min(x,y)で行い、c,dの昇順、a,bの降順にマッチング
    ABI=[0]*n
    CDI=[0]*n
    for i in range(n):
        a,b=ABorg[i]
        ABI[i]=(a,b,0)
        c,d=CDorg[i]
        CDI[i]=(c,d,1)
    X=ABI+CDI
    X.sort(lambda x:x[0]+x[1])

    # print(X)
    score=0
    for i in range(2*n):
        if(X[i][2]==0): continue
        c,d=X[i][0],X[i][1]
        for j in range(i-1,-1,-1):
            if(X[j][2]==1): continue
            a,b=X[j][0],X[j][1]
            if(a<c and b<d):
                score+=1
                X[j]=(INF,INF,INF)
                break
    ans=max(ans,score)

    print(ans)
resolve()

Submission status: Wrong Answer

Solution code:
n=int(input())

ll = sorted([list(map(int, input().split())) for _ in range(n)], key=lambda x: -x[1])

mm=sorted([list(map(int,input().split())) for _ in range(n)])
count_num=0
for i,j in mm:
  for k,h in ll:
    if k<=i and h<=j:
      count_num+=1
      ll.remove([k,h])
      break
print(n,ll,mm,count_num)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=[]
for i in range(n):
  l1=list(map(int,input().split()))
  l.append(l1+["a",0])
for i in range(n):
  l1=list(map(int,input().split()))
  l.append(l1+["b"])
count=0
for i in range(2*n):
  if l[i][2]=="a":
    pass
  else:#bが来たら
    num=l[i][1]
    min=100
    index=-1
    if i==0:
      pass
    else: 
      for j in range(0,i):#0~i-1までをみる
        if l[j][2]=="a":
          if l[j][3]==0:
            if min>num-l[j][1] and num>l[j][1]:
              min=num-l[j][1]
              index=j
      if index!=-1:
        l[index][3]=1
        count+=1
print(count)

Submission status: Wrong Answer

Solution code:
import numpy as np


def main():
    N = int(input())
    red = np.zeros([N, 3])
    blue = np.zeros([N, 3])

    for i in range(N):
        red[i, 0:2] = list(map(int, input().split()))

    for i in range(N):
        blue[i, 0:2] = list(map(int, input().split()))

    blue = blue[np.argsort(blue[:, 0])]
    red = red[np.argsort(red[:, 1])[::-1]]

    d = np.zeros([N, 3])
    cnt = 0

    for i in range(N):
        d[0:N, 0:2] = blue[i, 0:2] - red[0:N, 0:2]
        d[:, 2] = d[:, 0] + d[:, 1]

        if np.any((d[:, 0] > 0) & (d[:, 1] > 0)):
            dd = d[(d[:, 0] > 0) & (d[:, 1] > 0)]
            dd = dd[np.argsort(dd[:, 1])]
            ind = np.where(d == dd[0])
            row = ind[0][0]
            red[row, :] = 10**9
            cnt += 1

    print(cnt)


main()

Submission status: Wrong Answer

Solution code:
import numpy as np


def main():
    N = int(input())
    red = np.zeros([N, 3])
    blue = np.zeros([N, 3])

    for i in range(N):
        red[i, 0:2] = list(map(int, input().split()))

    for i in range(N):
        blue[i, 0:2] = list(map(int, input().split()))

    blue = blue[np.argsort(blue[:, 0])]
    red = red[np.argsort(red[:, 1])[::-1]]

    d = np.zeros([N, 3])
    cnt = 0

    for i in range(N):
        d[0:N, 0:2] = blue[i, 0:2] - red[0:N, 0:2]
        d[:, 2] = d[:, 0] + d[:, 1]
        print(blue[i, :])
        print(red[:, :])
        print(d)


        if np.any((d[:, 0] > 0) & (d[:, 1] > 0)):
            dd = d[(d[:, 0] > 0) & (d[:, 1] > 0)]
            dd = dd[np.argsort(dd[:, 1])]
            ind = np.where(d == dd[0])
            row = ind[0][0]
            red[row, :] = 10**9
            cnt += 1

    print(cnt)


main()

Submission status: Wrong Answer

Solution code:
import numpy as np


def main():
    N = int(input())
    red = np.zeros([N, 3])
    blue = np.zeros([N, 3])

    for i in range(N):
        red[i, 0:2] = list(map(int, input().split()))

    for i in range(N):
        blue[i, 0:2] = list(map(int, input().split()))

    blue = blue[np.argsort(blue[:, 0])]
    red = red[np.argsort(red[:, 1])]

    d = np.zeros([N, 3])
    cnt = 0

    for i in range(N):
        d[0:N, 0:2] = blue[i, 0:2] - red[0:N, 0:2]
        d[:, 2] = d[:, 0] + d[:, 1]

        if np.any((d[:, 0] > 0) & (d[:, 1] > 0)):
            dd = d[(d[:, 0] > 0) & (d[:, 1] > 0)]
            dd = dd[np.argsort(dd[:, 1])]
            ind = np.where(d == dd[0])
            row = ind[0][0]
            red[row, :] = 10**9
            cnt += 1

    print(cnt)


main()