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())
class Cumulative_Sum_2D:
    def __init__(self, a):
        lai = len(a)
        laj = len(a[0])
        self.s = [[0] * (laj + 1) for _ in range(lai + 1)]
        for i in range(lai):
            for j in range(laj):
                self.s[i+1][j+1] = self.s[i+1][j] + a[i][j]
        for i in range(lai):
            for j in range(laj):
                self.s[i+1][j+1] += self.s[i][j+1]
    def sum(self, li, lj, ri, rj):
        s = self.s
        return s[ri][rj] - s[li][rj] - s[ri][lj] + s[li][lj]

size = (2 * n + 2)
ab = [[0] * size for _ in range(size)]
cd = [[0] * size for _ in range(size)]
cdlist = []
for _ in range(n):
    xi, yi = map(int, input().split())
    ab[xi][yi] += 1
for _ in range(n):
    xi, yi = map(int, input().split())
    cd[xi][yi] += 1
    cdlist.append((xi,yi))
csab = Cumulative_Sum_2D(ab)
cscd = Cumulative_Sum_2D(cd)
#import numpy as np
#print(np.array(csab.s))
#print(np.array(cscd.s))
ans = 0
for ci,di in cdlist:
    if cscd.sum(0,0,ci+1,di+1) <= csab.sum(0,0,ci+1,di+1):
        ans += 1
    #print(ci,di,cscd.sum(0,0,ci+1,di+1),csab.sum(0,0,ci+1,di+1))
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
red = []
for i in range(N):
    a, b = map(int, input().split())
    red.append((a, b))
red = sorted(red, key=lambda x: x[0] + x[1], reverse=True)
# print(red)

blue = []
for i in range(N):
    a, b = map(int, input().split())
    blue.append((a, b))
blue = sorted(blue, key=lambda x: x[0] + x[1])
# print(blue)

count = 0
for i in range(N):
    b = blue[i]
    # print("{}".format(b))
    for j in range(len(red)):
        r = red[j]
        # print("{}".format(r))
        if r[0] < b[0] and r[1] < b[1]:
            # print("{}:{}".format(b, r))
            count += 1
            red.pop(j)
            break

print(count)

Submission status: Wrong Answer

Solution code:
n=int(input())
red=[list(map(int,input().split())) for _ in range(n)]
blue=[list(map(int,input().split())) for _ in range(n)]
red.sort()
blue.sort()
 
p=0
for bb in blue:
  lis=[-1,-1]
  for rr in red:
    if rr[0]<bb[0] and rr[1]<bb[1] and lis[1]<rr[1]:
      lis=rr
    if lis!=[-1,-1]:
      red.remove(rr)
      p+=1
print(p)

Submission status: Wrong Answer

Solution code:
n=int(input())
red=[list(map(int,input().split())) for _ in range(n)]
blue=[list(map(int,input().split())) for _ in range(n)]
red.sort(reverse=True)
blue.sort()

p=0
for bb in blue:
  for rr in red:
    if rr[0]<bb[0] and rr[1]<bb[1]:
      red.remove(rr)
      p+=1
      break
print(p)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left

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()
A = []
used = [False] * (n)
for i in range(n):
    A.append(AB[i][0])
cnt = 0
for i in range(n):
    c, d = CD[i]
    pos = bisect_left(A, c)
    delta = 10 ** 10
    kouho = -1
    for j in range(pos):
        if used[j]:
            continue
        a, b = AB[j]
        temp = d - b
        if delta >= temp:
            kouho = j
            delta = min(temp, delta)
    if kouho >= 0:
        used[kouho] = True
        cnt += 1
print(cnt)

Submission status: Wrong Answer

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

# print(*CD,sep='\n',end='\n---\n')
# print(*sorted(CD, key=lambda x: x[0]),sep='\n',end='\n---\n')
# CD.sort(key=lambda x: x[1])
# CD.sort(key=lambda x: x[0])
CD.sort()
# print(*CD,sep='\n',end='\n---\n')
# print(*AB,sep='\n',end='\n---\n')
AB.sort(key=lambda x: x[1])
# print(*AB,sep='\n',end='\n---\n')

dim_r = [[] for _ in range(n)]
dim_b = [[] for _ in range(n)]
# cnt_r = [0]*n
# cnt_b = [0]*n
for b in range(n):
    bx, by = CD[b]
    for r in range(n):
        rx, ry = AB[r]
        if rx < bx and ry < by:
            dim_r[r] += [b]
            dim_b[b] += [r]
            # cnt_b[b] += 1
            # cnt_r[r] += 1

# print(n)
# print(*AB,sep='\n',end='\n---\n')
# print(*CD,sep='\n',end='\n---\n')
# print(*dim_r,sep='\n',end='\n---\n')
# print(*dim_b,sep='\n',end='\n---\n')
# # print(cnt_b,end='\n---\n')

ans = 0

inf = 1000000000
vis_r = [False]*(n)
for b in range(n):
    min_rc = inf
    min_r = -1
    for r in dim_b[b]:
        if vis_r[r]: continue
        rc = len(dim_r[r])
        if min_rc > rc:
            min_rc = rc
            min_r = r
    if min_r >= 0:
        vis_r[min_r] = True
        ans += 1

print(ans)

Submission status: Wrong Answer

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

# print(*CD,sep='\n',end='\n---\n')
# print(*sorted(CD, key=lambda x: x[0]),sep='\n',end='\n---\n')
# CD.sort(key=lambda x: x[1])
# CD.sort(key=lambda x: x[0])
CD.sort()
# print(*CD,sep='\n',end='\n---\n')
# print(*AB,sep='\n',end='\n---\n')
AB.sort(key=lambda x: x[1])
# print(*AB,sep='\n',end='\n---\n')

dim_r = [[] for _ in range(n)]
dim_b = [[] for _ in range(n)]
# cnt_r = [0]*n
# cnt_b = [0]*n
for b in range(n):
    bx, by = CD[b]
    for r in range(n):
        rx, ry = AB[r]
        if rx < bx and ry < by:
            dim_r[r] += [b]
            dim_b[b] += [r]
            # cnt_b[b] += 1
            # cnt_r[r] += 1

# print(n)
# print(*AB,sep='\n',end='\n---\n')
# print(*CD,sep='\n',end='\n---\n')
# print(*dim_r,sep='\n',end='\n---\n')
# print(*dim_b,sep='\n',end='\n---\n')
# # print(cnt_b,end='\n---\n')

ans = 0

inf = 1000000000
# vis_r = [False]*(n)
vis_b = [False]*(n)
for r in range(n):
    min_bc = inf
    min_b = -1
    # print('r',r)
    for b in dim_r[r]:
        if vis_b[b]: continue
        # print('b',b)
        bc = len(dim_b[b])
        # print('bc',bc)
        # print(min_bc,bc)
        if min_bc > bc:
            min_bc = bc
            min_b = b
    if min_b >= 0:
        vis_b[min_b] = True
        ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
n, *ABCD = map(int, open(0).read().split())
AB = sorted([(a, b) for a, b in zip(ABCD[:2*n:2], ABCD[1:2*n:2])])
CD = sorted([(c, d) for c, d in zip(ABCD[2*n::2], ABCD[2*n+1::2])])

table = np.zeros((n, n), dtype=np.int)
for i in range(n):
    a, b = AB[i]
    for j in range(n):
        c, d = CD[j]
        if a < c and b < d:
            table[i, j] = 1

table = table[:, np.any(table, axis=0)]
table = table[np.any(table, axis=1), :]
E = []
while np.any(table):
    i = np.argmin(np.sum(table, axis=0))
    x = np.sum(table, axis=1)[table[:, i] == 0] = 10**5
    j = np.argmin(x)
    table = np.delete(table, i, 1)
    table = np.delete(table, j, 0)
    table = table[:, np.any(table, axis=0)]
    table = table[np.any(table, axis=1), :]
    E.append((i, j))
print(len(E))

Submission status: Wrong Answer

Solution code:
import numpy as np
n, *ABCD = map(int, open(0).read().split())
AB = sorted([(a, b) for a, b in zip(ABCD[:2*n:2], ABCD[1:2*n:2])])
CD = sorted([(c, d) for c, d in zip(ABCD[2*n::2], ABCD[2*n+1::2])])

table = np.zeros((n, n), dtype=np.int)
for i in range(n):
    a, b = AB[i]
    for j in range(n):
        c, d = CD[j]
        if a < c and b < d:
            table[i, j] = 1

x = np.any(table, axis=0)
table = table[:, x]

E = []
while np.any(table):
    i = np.argmin(np.sum(table, axis=0))
    j = np.argmax(table[:, i])
    table = np.delete(table, i, 1)
    table = np.delete(table, j, 0)
    x = np.any(table, axis=0)
    table = table[:, x]
    E.append((i, j))
print(len(E))

Submission status: Wrong Answer

Solution code:
import numpy as np
n, *ABCD = map(int, open(0).read().split())
AB = sorted([(a, b) for a, b in zip(ABCD[:2*n:2], ABCD[1:2*n:2])])
CD = sorted([(c, d) for c, d in zip(ABCD[2*n::2], ABCD[2*n+1::2])])

table = np.zeros((n, n), dtype=np.int)
for i in range(n):
    a, b = AB[i]
    for j in range(n):
        c, d = CD[j]
        if a < c and b < d:
            table[i, j] = 1

x = np.any(table, axis=0)
table = table[x, :]
table = table[:, x]

E = []
while len(table):
    i = np.argmin(np.sum(table, axis=0))
    j = np.argmax(table[:, i])
    table = np.delete(table, i, 1)
    table = np.delete(table, j, 0)
    x = np.any(table, axis=0)
    table = table[x, :]
    table = table[:, x]
    E.append((i, j))
print(len(E))

Submission status: Wrong Answer

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

dim_r = [[] for _ in range(n)]
# dim_b = [[] for _ in range(n)]
cnt_r = [0]*n
cnt_b = [0]*n
for r in range(n):
    rx, ry = AB[r]
    for b in range(n):
        bx, by = CD[b]
        # print('rx,bx,ry,by',rx,bx,ry,by)
        if rx < bx and ry < by:
            dim_r[r] += [b]
            # dim_b[b] += [r]
            cnt_b[b] += 1
            cnt_r[r] += 1


# print(cnt_r)
cnt_to_r = [[] for _ in range(n+1)] # count[0,n] -> r index
for r in range(n):
    cnt_to_r[cnt_r[r]] += [r]
# print(cnt_to_r)

# print(n)
# print(*AB,sep='\n',end='\n---\n')
# print(*CD,sep='\n',end='\n---\n')
# print(*dim_r,sep='\n',end='\n---\n')
# # print(*dim_b,sep='\n',end='\n---\n')
# print(cnt_b,end='\n---\n')

ans = 0

inf = 1000000000
# vis_r = [False]*(n)
vis_b = [False]*(n)
# for r in range(n):

for cnt in range(n+1): # count[0,n]
    for r in cnt_to_r[cnt]:
        min_bc = inf
        min_b = -1
        # print('r',r)
        for b in dim_r[r]:
            if vis_b[b]: continue
            # print('b',b)
            # bc = len(dim_b[b])
            bc = cnt_b[b]
            # print('bc',bc)
            # print(min_bc,bc)
            # if min_bc >= bc: # wa 3?
            if min_bc > bc: # wa 2?
                min_bc = bc
                min_b = b
        if min_b >= 0:
            vis_b[min_b] = True
            cnt_b[min_b] -= 1
            ans += 1

print(ans)

Submission status: Wrong Answer

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

dim_r = [[] for _ in range(n)]
# dim_b = [[] for _ in range(n)]
cnt_b = [0]*n
for r in range(n):
    rx, ry = AB[r]
    for b in range(n):
        bx, by = CD[b]
        # print('rx,bx,ry,by',rx,bx,ry,by)
        if rx < bx and ry < by:
            dim_r[r] += [b]
            # dim_b[b] += [r]
            cnt_b[b] += 1

# for b in range(n):
#     bx, by = CD[b]
#     for r in range(n):
#         rx, ry = AB[r]
#         # print('rx,bx,ry,by',rx,bx,ry,by)
#         if rx < bx and ry < by:
#             dim_b[b] += [r]

# print(n)
# print(*AB,sep='\n',end='\n---\n')
# print(*CD,sep='\n',end='\n---\n')
# print(*dim_r,sep='\n',end='\n---\n')
# # print(*dim_b,sep='\n',end='\n---\n')
# print(cnt_b,end='\n---\n')

ans = 0

inf = 1000000000
# vis_r = [False]*(n)
vis_b = [False]*(n)
for r in range(n):
    min_bc = inf
    min_b = -1
    # print('r',r)
    for b in dim_r[r]:
        if vis_b[b]: continue
        # print('b',b)
        # bc = len(dim_b[b])
        bc = cnt_b[b]
        # print('bc',bc)
        # print(min_bc,bc)
        if min_bc >= bc: # wa 3?
        # if min_bc > bc: # wa 2?
            min_bc = bc
            min_b = b
    if min_b >= 0:
        vis_b[min_b] = True
        cnt_b[min_b] -= 1
        ans += 1

print(ans)

Submission status: Wrong Answer

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

dim_r = [[] for _ in range(n)]
# dim_b = [[] for _ in range(n)]
cnt_b = [0]*n
for r in range(n):
    rx, ry = AB[r]
    for b in range(n):
        bx, by = CD[b]
        # print('rx,bx,ry,by',rx,bx,ry,by)
        if rx < bx and ry < by:
            dim_r[r] += [b]
            # dim_b[b] += [r]
            cnt_b[b] += 1

# for b in range(n):
#     bx, by = CD[b]
#     for r in range(n):
#         rx, ry = AB[r]
#         # print('rx,bx,ry,by',rx,bx,ry,by)
#         if rx < bx and ry < by:
#             dim_b[b] += [r]

# print(n)
# print(*AB,sep='\n',end='\n---\n')
# print(*CD,sep='\n',end='\n---\n')
# print(*dim_r,sep='\n',end='\n---\n')
# # print(*dim_b,sep='\n',end='\n---\n')
# print(cnt_b,end='\n---\n')

ans = 0

inf = 1000000000
# vis_r = [False]*(n)
vis_b = [False]*(n)
for r in range(n):
    min_bc = inf
    min_b = -1
    # print('r',r)
    for b in dim_r[r]:
        if vis_b[b]: continue
        # print('b',b)
        # bc = len(dim_b[b])
        bc = cnt_b[b]
        # print('bc',bc)
        # print(min_bc,bc)
        # if min_bc >= bc: # wa 3?
        if min_bc > bc: # wa 2?
            min_bc = bc
            min_b = b
    if min_b >= 0:
        vis_b[min_b] = True
        cnt_b[min_b] -= 1
        ans += 1

print(ans)

Submission status: Wrong Answer

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

dim_r = [[] for _ in range(n)]
dim_b = [[] for _ in range(n)]
for r in range(n):
    rx, ry = AB[r]
    for b in range(n):
        bx, by = CD[b]
        # print('rx,bx,ry,by',rx,bx,ry,by)
        if rx < bx and ry < by:
            dim_r[r] += [b]
            # dim_b[b] += [r]

for b in range(n):
    bx, by = CD[b]
    for r in range(n):
        rx, ry = AB[r]
        # print('rx,bx,ry,by',rx,bx,ry,by)
        if rx < bx and ry < by:
            dim_b[b] += [r]

# print(n)
# print(*AB,sep='\n',end='\n---\n')
# print(*CD,sep='\n',end='\n---\n')
# print(*dim_r,sep='\n',end='\n---\n')
# print(*dim_b,sep='\n',end='\n---\n')

ans = 0

inf = 1000000000
# vis_r = [False]*(n)
vis_b = [False]*(n)
for r in range(n):
    min_bc = inf
    min_b = -1
    # max_bc = 0
    # max_b = -1
    # print('r',r)
    for b in dim_r[r]:
        if vis_b[b]: continue
        # print('b',b)
        bc = len(dim_b[b])
        # print('bc',bc)
        # print(min_bc,bc)
        # if min_bc >= bc: # wa 3?
        if min_bc > bc: # wa 2?
            min_bc = bc
            min_b = b
    if min_b >= 0:
        vis_b[min_b] = True
        ans += 1
        # if max_bc < bc:
        #     max_bc = bc
        #     max_b = b
    # if max_b >= 0:
    #     vis_b[max_b] = True
    #     ans += 1

print(ans)

Submission status: Wrong Answer

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

dim_r = [[] for _ in range(n)]
dim_b = [[] for _ in range(n)]
for r in range(n):
    rx, ry = AB[r]
    for b in range(n):
        bx, by = CD[b]
        # print('rx,bx,ry,by',rx,bx,ry,by)
        if rx < bx and ry < by:
            dim_r[r] += [b]
            dim_b[b] += [r]

# print(n)
# print(AB)
# print(CD)
# print(dim_r)
# print(dim_b)

ans = 0

inf = 1000000000
# vis_r = [False]*(n)
vis_b = [False]*(n)
for r in range(n):
    min_bc = inf
    min_b = -1
    # print('r',r)
    for b in dim_r[r]:
        if vis_b[b]: continue
        # print('b',b)
        bc = len(dim_b[b])
        # print('bc',bc)
        # print(min_bc,bc)
        if min_bc >= bc:
            min_bc = bc
            min_b = b
    if min_b >= 0:
        vis_b[min_b] = True
        ans += 1

print(ans)

Submission status: Wrong Answer

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

dim_r = [[] for _ in range(n)]
dim_b = [[] for _ in range(n)]
for r in range(n):
    rx, ry = AB[r]
    for b in range(n):
        bx, by = CD[b]
        # print('rx,bx,ry,by',rx,bx,ry,by)
        if rx < bx and ry < by:
            dim_r[r] += [b]
            dim_b[b] += [r]

# print(n)
# print(AB)
# print(CD)
# print(dim_r)
# print(dim_b)

ans = 0

inf = 1000000000
# vis_r = [False]*(n)
vis_b = [False]*(n)
for r in range(n):
    min_bc = inf
    min_b = -1
    # print('r',r)
    for b in dim_r[r]:
        if vis_b[b]: continue
        # print('b',b)
        bc = len(dim_b[b])
        # print('bc',bc)
        # print(min_bc,bc)
        if min_bc > bc:
            min_bc = bc
            min_b = b
    if min_b >= 0:
        vis_b[min_b] = True
        ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    red = {tuple(int(i) for i in input().split()): False for _ in range(n)}
    blue = {tuple(int(i) for i in input().split()): False for _ in range(n)}
    c = 0
    for d in range(1, 2 * n):
        for r in red:
            if red[r]:
                continue
            x, y = r
            for e in range(1, d + 1):
                p = x + e, y + d
                if p in blue and not blue[p]:
                    red[r] = True
                    blue[p] = True
                    c += 1
                    break
                p = x + d, y + e
                if p in blue and not blue[p]:
                    red[r] = True
                    blue[p] = True
                    c += 1
                    break
    print(c)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
ps = []
for _ in range(n):
    a, b = map(int, input().split())
    ps.append([a, b, 0])
for _ in range(n):
    c, d = map(int, input().split())
    ps.append([c, d, 1])
ps = sorted(ps, key=lambda x: x[0])    

c = 0
for i in range(1, len(ps)):
    b = ps[i]
    # redもしくは、既にペアが決まっていたら飛ばす
    if b[2] == 0 or b[2] == 2:
        continue

    j = 0
    maxy = -1
    rec = -1
    while j < i:
        r = ps[j]
        # blue もしくは、既にペアが決まっていあら飛ばす
        if r[2] == 1 or r[2] == 2:
            j += 1
            continue

        if r[1] > maxy:
            maxy = r[1]
            rec = j

        j += 1

    if rec == -1:
        continue
    
    # ペアになったものを記録
    ps[rec][2] = 2
    c += 1

print(c)

Submission status: Wrong Answer

Solution code:
n = int(input())
red_points = [[int(j) for j in input().split()] for i in range(n)]
blue_points = [[int(j) for j in input().split()] for i in range(n)]

count = 0

for a, b in sorted(red_points, key=lambda x: x[0] + x[1], reverse=True):

    tmp = [((blue_p[0]-a) + (blue_p[1]-b), i)
           for i, blue_p in enumerate(blue_points)
           if a < blue_p[0] and b < blue_p[1]]

    if len(tmp) > 0:
        count += 1

        p = min(tmp, key=lambda x:x[0])
        blue_points.pop(p[1])

print(count)

Submission status: Wrong Answer

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

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache


#############
# Constants #
#############

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

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()

#####Shorten#####
def DD(arg): return defaultdict(arg)


#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####MakePrimes######
def make_primes(N):
  max = int(math.sqrt(N))
  seachList = [i for i in range(2,N+1)]
  primeNum = []
  while seachList[0] <= max:
    primeNum.append(seachList[0])
    tmp = seachList[0]
    seachList = [i for i in seachList if i % tmp != 0]
  primeNum.extend(seachList)
  return primeNum

#####GCD#####
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############
N = I()
R = ILL(N)
B = ILL(N)

graphR = [[] for _ in range(N)]
graphB = [[] for _ in range(N)]

for i in range(N):
  for j in range(N):
    if R[i][0] < B[j][0] and R[i][1] < B[j][1]:
      graphR[i].append(j)
      graphB[j].append(i)

ans1 = 0
while graphR:
  joho = [[len(l),l] for l in graphR]
  joho.sort(reverse=True)
  graphR = [l for n,l in joho]
  l = graphR.pop()
  if l:
    x = l.pop()
    ans1 += 1
    for r in graphR:
      if x in r:
        r.remove(x)
ans2 = 0
while graphB:
  joho = [[len(l),l] for l in graphB]
  joho.sort(reverse=True)
  graphB = [l for n,l in joho]
  l = graphB.pop()
  if l:
    x = l.pop()
    ans2 += 1
    for r in graphB:
      if x in r:
        r.remove(x)        
        
print(min(ans1,ans2))

Submission status: Wrong Answer

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

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache


#############
# Constants #
#############

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

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()

#####Shorten#####
def DD(arg): return defaultdict(arg)


#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####MakePrimes######
def make_primes(N):
  max = int(math.sqrt(N))
  seachList = [i for i in range(2,N+1)]
  primeNum = []
  while seachList[0] <= max:
    primeNum.append(seachList[0])
    tmp = seachList[0]
    seachList = [i for i in seachList if i % tmp != 0]
  primeNum.extend(seachList)
  return primeNum

#####GCD#####
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############
N = I()
R = ILL(N)
B = ILL(N)

graphR = [[] for _ in range(N)]
graphB = [[] for _ in range(N)]

for i in range(N):
  for j in range(N):
    if R[i][0] < B[j][0] and R[i][1] < B[j][1]:
      graphR[i].append(j)
      graphB[j].append(i)

ans = 0
while graphR:
  joho = [[len(l),l] for l in graphR]
  joho.sort(reverse=True)
  graphR = [l for n,l in joho]
  l = graphR.pop()
  if l:
    x = l.pop()
    ans += 1
    for r in graphR:
      if x in r:
        r.remove(x)
print(ans)

Submission status: Wrong Answer

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

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache


#############
# Constants #
#############

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

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()

#####Shorten#####
def DD(arg): return defaultdict(arg)


#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####MakePrimes######
def make_primes(N):
  max = int(math.sqrt(N))
  seachList = [i for i in range(2,N+1)]
  primeNum = []
  while seachList[0] <= max:
    primeNum.append(seachList[0])
    tmp = seachList[0]
    seachList = [i for i in seachList if i % tmp != 0]
  primeNum.extend(seachList)
  return primeNum

#####GCD#####
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############
N = I()
R = ILL(N)
B = ILL(N)

graphR = [[] for _ in range(N)]
graphB = [[] for _ in range(N)]

for i in range(N):
  for j in range(N):
    if R[i][0] < B[j][0] and R[i][1] < B[j][1]:
      graphR[i].append(j)
      graphB[j].append(i)

ans = 0
while graphR:
  l = graphR.pop()
  if l:
    x = l.pop()
    ans += 1
    for r in graphR:
      if x in r:
        r.remove(x)
print(ans)