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())
R = [list(map(int, input().split())) for i in range(n)]
B = [list(map(int, input().split())) for i in range(n)]
B.sort(key = lambda x:x[0])
R.sort(key = lambda x:x[1], reverse = True)

#print(R)
ans = 0
for bx,by in B:
 #   print(bx,by)
    for i in range(len(R)):
        if R[i][0] < bx:
  #          print(R[i],"とマッチ")
            del R[i]
            ans += 1
            break
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())


n = ni()
ab = [tuple(li()) for i in range(n)]
cd = [tuple(li()) for i in range(n)]

ab.sort(key=lambda x: x[0])
cd.sort(key=lambda x: x[1])

cd_used = [False]*n

ans = 0
for ai, bi in ab:
    for j, (cj, dj) in enumerate(cd):
        if ai < cj and bi < dj and (not cd_used[j]):
            cd_used[j] = True
            ans += 1

            break

print(ans)

Submission status: Wrong Answer

Solution code:
import copy
N = int(input())
R = []
for i in range(N):
    a,b = map(int,input().split())
    R.append([a,b])
B = []
for i in range(N):
    c,d = map(int,input().split())
    B.append([c,d])
######
INF = 10**10
R.sort(key=lambda x:min(x[0],x[1]))
B.sort(key=lambda x:min(x[0],x[1]))
ans = 0
for r in range(N):
    for b in range(N):
        if R[r][0]<B[b][0] and R[r][1]<B[b][1]:
            ans+=1
            B[b][0]=-INF
            B[b][1]=-INF
            break
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
R=sorted([list(map(int,input().split())) for i in range(N)])
B=sorted([list(map(int,input().split())) for i in range(N)])
ans=0
for i in range(N-1,-1,-1):
    a=[-1,-1]
    x=-1
    for j in range(len(R)):
        if B[i][0]>R[j][0] and B[i][1]>R[j][1]:
            if a[1]<R[j][1]:
                a=R[j]
                x=j
    if x>=0:
        del R[x]
        ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
R=sorted([list(map(int,input().split())) for i in range(N)])
B=sorted([list(map(int,input().split())) for i in range(N)])
ans=0
for i in range(N-1,-1,-1):
    a=[-1,-1]
    x=-1
    for j in range(len(R)):
        if B[i][0]>R[j][0] and B[i][1]>R[j][1]:
            if a[1]<R[j][1]:
                a=R[j]
                x=j
    if x>=0:
        print(i,x)
        del R[x]
        ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
R=sorted([list(map(int,input().split())) for i in range(N)])
B=sorted([list(map(int,input().split())) for i in range(N)])
ans=0
for i in range(N-1,-1,-1):
    for j in range(len(R)-1,-1,-1):
        if B[i][0]>R[j][0] and B[i][1]>R[j][1]:
            del R[j]
            ans+=1
            break
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
ab = [tuple(map(int, input().split())) for _ in range(n)]
cd = [tuple(map(int, input().split())) for _ in range(n)]
ab.sort()
cd.sort()
ans, i, j = 0, 0, 0


while i < n and j < n:
        if ab[i][0] < cd[j][0] and ab[i][1] < cd[j][1]:
            ans += 1
        i += 1
        j += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
ab = [tuple(map(int, input().split())) for _ in range(n)]
cd = [tuple(map(int, input().split())) for _ in range(n)]
ab.sort()
cd.sort()
ans, i, j = 0, 0, 0

while i < n and j < n:
    if ab[i] < cd[j]:
        ans += 1
    i += 1
    j += 1

print(ans)

Submission status: Wrong Answer

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

AB = sorted(AB, key=lambda x:x[1])
CD = sorted(CD, key=lambda x:x[0])

result = 0

for c, d in CD:
    xs = [x for x in AB if x[0] < c]
    if xs:
        AB.remove(xs[-1])
        result += 1

print(result)

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=sorted(red,key=lambda x:x[0]+x[1])
cnt=0
for i in range(n-1,-1,-1):
  rx=red[i][0]
  ry=red[i][1]
  l=len(blue)
  pos=-1
  tmp=10**10
  for j in range(l-1,-1,-1):
    bx=blue[j][0]
    by=blue[j][1]
    if bx>rx and by>ry:
      diff=(bx-rx)**2+(by-ry)**2
      if diff<tmp:
        tmp=diff
        pos=j
  if pos!=-1:
    cnt+=1
    blue.pop(pos)
print(cnt)

Submission status: Wrong Answer

Solution code:
import copy

n=int(input())
red=[list(map(int,input().split())) for _ in range(n)]
blue=[list(map(int,input().split())) for _ in range(n)]
red2=copy.deepcopy(red)
blue2=copy.deepcopy(blue)
red=sorted(red,key=lambda x:x[0])
red=sorted(red,key=lambda x:x[1])
blue=sorted(blue,key=lambda x:x[0])
blue=sorted(blue,key=lambda x:x[1])
red2=sorted(red2,key=lambda x:x[1])
red2=sorted(red2,key=lambda x:x[0])
blue2=sorted(blue2,key=lambda x:x[1])
blue2=sorted(blue2,key=lambda x:x[0])
cnt=0
cnt2=0
for i in range(n-1,-1,-1):
  bx=blue[i][0]
  by=blue[i][1]
  l=len(red)
  for j in range(l-1,-1,-1):
    rx=red[j][0]
    ry=red[j][1]
    if bx>rx and by>ry:
      cnt+=1
      red.pop(j)
      break
for i in range(n-1,-1,-1):
  bx=blue2[i][0]
  by=blue2[i][1]
  l=len(red2)
  for j in range(l-1,-1,-1):
    rx=red2[j][0]
    ry=red2[j][1]
    if bx>rx and by>ry:
      cnt2+=1
      red2.pop(j)
      break
print(max(cnt,cnt2))

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=sorted(red,key=lambda x:x[0])
red=sorted(red,key=lambda x:x[1])
blue=sorted(blue,key=lambda x:x[0])
blue=sorted(blue,key=lambda x:x[1])
cnt=0
for i in range(n-1,-1,-1):
  bx=blue[i][0]
  by=blue[i][1]
  l=len(red)
  for j in range(l-1,-1,-1):
    rx=red[j][0]
    ry=red[j][1]
    if bx>rx and by>ry:
      cnt+=1
      red.pop(j)
      break
print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())

a = []
for i in range(N):
  a.append([int(x) for x in input().split()])
  
c = []
for i in range(N):
  c.append([int(x) for x in input().split()])

a.sort(key=lambda x:(x[0]+x[1]),reverse = True)
c.sort(key=lambda x:(x[0]+x[1]),reverse = True)

z=[]
for x in range(N):
  for y in range(N):
    if a[x][0] < c[y][0] and a[x][1] < c[y][1] and c[y] not in z:
      z.append(c[y])
      break  

print(len(z))

Submission status: Wrong Answer

Solution code:
N = int(input())

a = []
for i in range(N):
  a.append([int(x) for x in input().split()])
  
c = []
for i in range(N):
  c.append([int(x) for x in input().split()])

a.sort(key=lambda x:(x[0]+x[1]))
c.sort(key=lambda x:(x[0]+x[1]))

p = 0
if [0,0] in a:
  del a[0]
  p += 1

z=[]
for x in range(len(a)):
  for y in range(N):
    if a[x][0] < c[y][0] and a[x][1] < c[y][1] and c[y] not in z:
      z.append(c[y])
      break  

print(len(z)+p)

Submission status: Wrong Answer

Solution code:
N = int(input())
ab, cd = [], []
for _ in range(N):
    a_, b_ = list(map(int, input().split()))
    ab.append([a_, b_])
for _ in range(N):
    c_, d_ = list(map(int, input().split()))
    cd.append([c_, d_])

v = [[0 for i in range(N)] for _ in range(N)]
vsum = [[0, i] for i in range(N)]

for i, x in enumerate(ab):
    for j, y in enumerate(cd):
        if (x[0] < y[0]) & (x[1] < y[1]):
            v[i][j] = 1
            vsum[i][0] += 1
vsum.sort()
ans = 0
for x, i in vsum:
    vvv = v[i]
    crit = []
    for j, v4 in enumerate(vvv):
        t = 0
        if v4 == 1:
            for k in range(N):
                if v[k][j] == 1:
                    t += 1
            crit.append([t, j])
    if len(crit) > 0:
        crit.sort()
        zero_i = crit[0][1]
        for k in range(N):
            v[k][zero_i] = 0
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
ab, cd = [], []
for _ in range(N):
    a_, b_ = list(map(int, input().split()))
    ab.append([a_, b_])
for _ in range(N):
    c_, d_ = list(map(int, input().split()))
    cd.append([c_, d_])

v = [[0 for i in range(N)] for _ in range(N)]
vsum = [[0, i] for i in range(N)]

for i, x in enumerate(ab):
    for j, y in enumerate(cd):
        if (x[0] < y[0]) & (x[1] < y[1]):
            v[i][j] = 1
            vsum[i][0] += 1
vsum.sort()
ans = 0
for x, i in vsum:
    vvv = v[i]
    f = False
    for j, v4 in enumerate(vvv):
        if f:
            break
        elif v4 == 1:
            for k in range(N):
                v[k][j] = 0
            f = True
            ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
v = [[[0, 0] for i in range(2 * N + 1)] for _ in range(2 * N + 1)]

for _ in range(N):
    x, y = map(int, input().split())
    v[x + 1][y + 1][0] = 1

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

for i in range(1, 2 * N + 1):
    v[i][0][0] += v[i - 1][0][0]
    v[0][i][0] += v[0][i - 1][0]

ans = 0
for i in range(1, 2 * N + 1):
    for j in range(1, 2 * N + 1):
        # v[i][j] += v[i-1][j-1] + (v[i-1][j] - v[i-1][j-1]) + (v[i][j-1] - v[i-1][j-1])
        v[i][j][0] += v[i - 1][j][0] + v[i][j - 1][0] - v[i - 1][j - 1][0]

        if (v[i][j][1] == 1) & (v[i][j][0] > 0):
            ans += 1
            v[i][j][0] -= 1
            v[i - 1][j - 1][0] -= 1
            # v[i-1][j][0] -= 1
            # v[i][j-1][0] -= 1

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
v = [[[0, 0] for i in range(2 * N + 1)] for _ in range(2 * N + 1)]

for _ in range(N):
    x, y = map(int, input().split())
    v[x + 1][y + 1][0] = 1

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

for i in range(1, 2 * N + 1):
    v[i][0][0] += v[i - 1][0][0]
    v[0][i][0] += v[0][i - 1][0]

ans = 0
for i in range(1, 2 * N + 1):
    for j in range(1, 2 * N + 1):
        # v[i][j] += v[i-1][j-1] + (v[i-1][j] - v[i-1][j-1]) + (v[i][j-1] - v[i-1][j-1])
        v[i][j][0] += v[i - 1][j][0] + v[i][j - 1][0] - v[i - 1][j - 1][0]

        if (v[i][j][1] == 1) & (v[i][j][0] > 0):
            ans += 1
            v[i][j][0] -= 1

print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
a,b,c,d,red,blue=[],[],[],[],[],[]
for i in range(N):
    ai,bi=list(map(int,input().split()))
    a.append(ai)
    b.append(bi)
for i in range(N):
    ci,di=list(map(int,input().split()))
    c.append(ci)
    d.append(di)
for i in range(N):
    red.append([a[i],b[i]])
    blue.append([c[i],d[i]])

cxy = []
for i in range(N):
    cxy.append(["r",red[i][0],red[i][1],0])
    cxy.append(["b",blue[i][0],blue[i][1],0])

cxy_sort = sorted(cxy, key=lambda x: x[1])

cnt=0
counter = 0
for i in range(N*2):
    min=1000
    for j in range(i+1,N*2):
        if cxy_sort[i][0] == "r" and cxy_sort[j][0] == "b" and cxy_sort[j][3] == 0 and cxy_sort[j][2] - cxy_sort[i][2] >0:
            abs = cxy_sort[j][2] - cxy_sort[i][2]
            if abs < min:
                min = abs
                counter = j
    if counter != 0:
        cxy_sort[counter][3] = 1
        cnt +=  1
    counter = 0

print(cnt)

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)]

pair = [[] for i in range(N)]
count = [0 for i in range(N)]
idx = 0
for i in red:
    ct = 0
    a, b = i
    for j in blue:
        c, d = j
        if a <= c and b <= d:
            pair[idx].append(j)
            ct += 1
            count[idx] += 1
    idx += 1

for i in range(N):
    if count[i] == 0:
        count[i] = 1000

ans = 0
while True:
    idx = count.index(min(count))
    if count[idx] == 1000:
        break
    ab = pair[idx].pop(0)
    pair[idx] = []
    count[idx] = 1000
    ans += 1
    idx = 0
    for i in pair:
        if ab in i:
            i.remove(ab)
            count[idx] -= 1
        idx += 1
    for i in range(N):
        if count[i] == 0:
            count[i] = 1000
            pair[i] = []

print(ans)

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)]

pair = [[] for i in range(N)]
count = [0 for i in range(N)]
idx = 0
for i in red:
    ct = 0
    a, b = i
    for j in blue:
        c, d = j
        if a <= c and b <= d:
            pair[idx].append(j)
            ct += 1
            count[idx] += 1
    idx += 1

for i in range(N):
    if count[i] == 0:
        count[i] = 1000

ans = 0
while True:
    idx = count.index(min(count))
    if count[idx] == 1000:
        break
    count[idx] -= 1
    if count[idx] == 0:
        count[idx] = 1000
    ab = pair[idx].pop(0)
    pair[idx] = []
    count[idx] = 1000
    ans += 1
    idx = 0
    for i in pair:
        if ab in i:
            i.remove(ab)
            count[idx] -= 1
        idx += 1
    for i in range(N):
        if count[i] == 0:
            count[i] = 1000

print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[list(map(int,input().split()))for i in range(n)]
b=[list(map(int,input().split()))for i in range(n)]
a.sort(key=lambda x:x[0])
b.sort(key=lambda x:x[1],reverse=1)
ans=0
i,j=0,0
while i<n and j<n:
  if a[i][0]>b[j][0]:
    j+=1
    continue
  elif a[i][1]>b[j][1]:
    i+=1
  else:
    ans+=1
    i+=1
    j+=1
print(ans)

Submission status: Wrong Answer

Solution code:
def MI(): return map(int, input().split())
def II(): return int(input())
def IS(): return input()
def LI(): return list(map(int, input().split()))


n = II()
reds = [LI() for i in range(n)]
blues = [LI() for i in range(n)]
count = 0

reds.sort(key=lambda x:(x[0], x[1]), reverse=True)
blues.sort(key=lambda x:(x[0], x[1]), reverse=True)

for red in reds:
    for blue in blues:
        if red[0] < blue[0] and red[1] < blue[1]:
            count += 1
            blues.pop(blues.index(blue))
            break
print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
red = []
blue = []
for i in range(N):
    x, y = map(int, input().split())
    red.append((x, y))
for i in range(N):
    x, y = map(int, input().split())
    blue.append((x, y))
red.sort(key=lambda x: x[0])
blue.sort(key=lambda x: x[0])
ans = 0
for i in range(N):
    index = -1
    for j in range(len(blue)):
        if red[i][0] >= blue[j][0]:
            continue
        elif red[i][1] < blue[j][1]:
            if index == -1 or blue[index][1] < blue[j][1]:
                index = j
    if index != -1:
        blue.remove(blue[index])
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
redpoint = [[int(_) for _ in input().split()] for _ in range(N)]
bluepoint = [[int(_) for _ in input().split()] for _ in range(N)]
blueflag = [True]*(N)
redpoint = sorted(redpoint, key=lambda x: (-x[0],-x[1]))
bluepoint = sorted(bluepoint, key=lambda x: (-x[0],-x[1]))
ans = 0

for i in redpoint:
    for j in range(N):
        if blueflag[j] and i[0] < bluepoint[j][0] and i[1] < bluepoint[j][1]:
            blueflag[j] = False
            ans += 1
            break

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
redpoint = [[int(_) for _ in input().split()] for _ in range(N)]
bluepoint = [[int(_) for _ in input().split()] for _ in range(N)]
blueflag = [True]*(N)
redpoint = sorted(redpoint, key=lambda x: (x[0]+x[1]))
bluepoint = sorted(bluepoint, key=lambda x: (x[0]+x[1]))
ans = 0

for i in redpoint:
    for j in range(N):
        if blueflag[j] and i[0] < bluepoint[j][0] and i[1] < bluepoint[j][1]:
            blueflag[j] = False
            ans += 1
            break

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

N = int(input())
redpoint = [[int(_) for _ in input().split()] for _ in range(N)]
bluepoint = [[int(_) for _ in input().split()] for _ in range(N)]
blueflag = [True]*(N)
redpoint = sorted(redpoint, key=lambda x: (x[0], x[1]))
bluepoint = sorted(bluepoint, key=lambda x: (x[0], x[1]))
ans = 0

for i in redpoint:
    for j in range(N):
        if blueflag[j] and i[0] < bluepoint[j][0] and i[1] < bluepoint[j][1]:
            blueflag[j] = False
            ans += 1
            break

print(ans)

Submission status: Wrong Answer

Solution code:
import bisect

N = int(input())
red = [[int(_) for _ in input().split()] for _ in range(N)]
blue = [[int(_) for _ in input().split()] for _ in range(N)]

red = sorted(red, key=lambda x: (x[0], x[1]))
blue = sorted(blue, key=lambda x: (x[0], x[1]))
bindex = -1
ans = 0

for i in red:
    tmp = bisect.bisect_right(blue, i)
    if tmp == N:
        break
    elif tmp > bindex:
        ans += 1
        bindex = tmp
    else:
        ans += 1
        bindex += 1
    
    if bindex == N-1:
        break

print(ans)

Submission status: Wrong Answer

Solution code:
import bisect

N = int(input())
red = [[int(_) for _ in input().split()] for _ in range(N)]
blue = [[int(_) for _ in input().split()] for _ in range(N)]

red = sorted(red, key=lambda x: (x[0], x[1]))
blue = sorted(blue, key=lambda x: (x[0], x[1]))
bindex = -1
ans = 0

for i in red:
    tmp = bisect.bisect_left(blue, i)
    if tmp == N:
        break
    elif tmp > bindex:
        ans += 1
        bindex = tmp
    else:
        ans += 1
        bindex += 1
    
    if bindex == N-1:
        break

print(ans)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left
n = int(input())
red = sorted([list(map(int, input().split())) for i in range(n)])
blue = sorted([list(map(int, input().split())) for i in range(n)])

ans = 0
for x,y, in blue:
    i = bisect_left([a[0] for a in red], x)
    use = sorted(red[:i], key=lambda x:x[1], reverse=True)
    if use:
        ans += 1
        red.remove(use[0])
print(ans)

Submission status: Wrong Answer

Solution code:
import copy
N = int(input())
L = []
for i in range(N):
  L.append(list(map(int,input().split())))
M = []
for i in range(N):
  M.append(list(map(int,input().split())))
L.sort()
M.sort()
MT = [True]*N
LT = [True]*N
ansA = 0
for i in range(N):
  curx = M[N-i-1][0]
  cury = M[N-i-1][1]
  for j in range(N-1,-1,-1):
    if LT[j] == True:
      if MT[N-i-1] == True:
        if curx >= L[j][0] and cury >= L[j][1]:
          LT[j] = False
          ansA += 1
          MT[N-i-1] = False
U = copy.deepcopy(L)
V = copy.deepcopy(M)          
U = sorted(U, key = lambda x:x[1])
V = sorted(V, key = lambda x:x[1])
UT = [True]*N
VT = [True]*N
ansB = 0
for i in range(N):
  curx = V[N-i-1][0]
  cury = V[N-i-1][1]
  for j in range(N-1,-1,-1):
    if UT[j] == True:
      if VT[N-i-1] == True:
        if curx >= U[j][0] and cury >= U[j][1]:
          UT[j] = False
          ansB += 1
          VT[N-i-1] = False
print(max(ansA,ansB))

Submission status: Wrong Answer

Solution code:
N = int(input())
L = []
for i in range(N):
  L.append(list(map(int,input().split())))
M = []
for i in range(N):
  M.append(list(map(int,input().split())))
L.sort()
M.sort()
MT = [True]*N
LT = [True]*N
ans = 0
for i in range(N):
  curx = M[N-i-1][0]
  cury = M[N-i-1][1]
  for j in range(N-1,-1,-1):
    if LT[j] == True:
      if MT[N-i-1] == True:
        if curx >= L[j][0] and cury >= L[j][1]:
          LT[j] = False
          ans += 1
          MT[N-i-1] = False
print(ans)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter

n = int(input())
red = []
blue = []
for i in range(n):
    a, b = map(int, input().split())
    red.append([a, b, min(a, b)])
for i in range(n):
    c, d = map(int, input().split())
    blue.append([c, d, min(c, d)])
red = sorted(red, key=itemgetter(2))
blue = sorted(blue, key=itemgetter(2))
red_x = set()
red_y = set()
blue_x = set()
blue_y = set()
for i in red:
    red_x.add(i[0])
    red_y.add(i[1])
for i in blue:
    blue_x.add(i[0])
    blue_y.add(i[1])
for i in blue:
    x = i[0]
    y = i[1]
    mini_x = min(red_x)
    mini_y = min(red_y)
    if x > mini_x and y > mini_y:
        for j in red:
            if j[0] in red_x and j[1] in red_y:
                if x > j[0] and y > j[1]:
                    red_x.discard(j[0])
                    red_y.discard(j[1])
                    break
for i in red:
    x = i[0]
    y = i[1]
    maxi_x = max(blue_x)
    maxi_y = max(blue_y)
    if x < maxi_x and y < maxi_y:
        for j in blue:
            if j[0] in blue_x and j[1] in blue_y:
                if x < j[0] and y < j[1]:
                    blue_x.discard(j[0])
                    blue_y.discard(j[1])
                    break
print(n - max(len(red_x), len(blue_x)))

Submission status: Wrong Answer

Solution code:
from operator import itemgetter

n = int(input())
red = []
blue = []
for i in range(n):
    a, b = map(int, input().split())
    red.append([a, b, min(a, b)])
for i in range(n):
    c, d = map(int, input().split())
    blue.append([c, d, min(c, d)])
red = sorted(red, key=itemgetter(2))
blue = sorted(blue, key=itemgetter(2))
red_x = set()
red_y = set()
blue_x = set()
blue_y = set()
for i in red:
    red_x.add(i[0])
    red_y.add(i[1])
for i in blue:
    blue_x.add(i[0])
    blue_y.add(i[1])
for i in blue:
    x = i[0]
    y = i[1]
    mini_x = min(red_x)
    mini_y = min(red_y)
    if x > mini_x and y > mini_y:
        for j in red:
            if j[0] in red_x and j[1] in red_y:
                if x > j[0] and y > j[1]:
                    red_x.discard(j[0])
                    red_y.discard(j[1])
                    break
print(n - len(red_x))

Submission status: Wrong Answer

Solution code:
N = int(input())
red_points = [tuple(map(int, input().split())) for i in range(N)]
blue_points = [tuple(map(int, input().split())) for i in range(N)]

red_points_count = {red_points[i]:0 for i in range(N)}
blue_points_count = {blue_points[i]:0 for i in range(N)}
for red in red_points:
    for blue in blue_points:
        if red[0] < blue[0] and red[1] < blue[1]:
            red_points_count[red] += 1
            blue_points_count[blue] += 1

red_points.sort(key=lambda x: red_points_count[x])
blue_points.sort(key=lambda x: blue_points_count[x])

count = 0

points_used = [False for i in range(N)]

for red in red_points:
    for i, blue in enumerate(blue_points):
        if not points_used[i] and red[0] < blue[0] and red[1] < blue[1]:
            count += 1
            points_used[i] = True
            break
            
print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
red_points = [tuple(map(int, input().split())) for i in range(N)]
blue_points = [tuple(map(int, input().split())) for i in range(N)]

red_points_count = {red_points[i]:0 for i in range(N)}
blue_points_count = {blue_points[i]:0 for i in range(N)}
for red in red_points:
    for blue in blue_points:
        if red[0] < blue[0] and red[1] < blue[1]:
            red_points_count[red] += 1
            blue_points_count[blue] += 1

red_points.sort(key=lambda x: red_points_count[x])
blue_points.sort(key=lambda x: -blue_points_count[x])

count = 0

points_used = [False for i in range(N)]

for red in red_points:
    for i, blue in enumerate(blue_points):
        if not points_used[i] and red[0] < blue[0] and red[1] < blue[1]:
            count += 1
            points_used[i] = True
            break
            
print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
red_points = [tuple(map(int, input().split())) for i in range(N)]
blue_points = [tuple(map(int, input().split())) for i in range(N)]

red_points_count = {red_points[i]:0 for i in range(N)}
blue_points_count = {blue_points[i]:0 for i in range(N)}
for red in red_points:
    for blue in blue_points:
        if red[0] < blue[0] and red[1] < blue[1]:
            red_points_count[red] += 1
            blue_points_count[blue] += 1

red_points.sort(key=lambda x: -red_points_count[x])
blue_points.sort(key=lambda x: blue_points_count[x])

count = 0

points_used = [False for i in range(N)]

for red in red_points:
    for i, blue in enumerate(blue_points):
        if not points_used[i] and red[0] < blue[0] and red[1] < blue[1]:
            count += 1
            points_used[i] = True
            break
            
print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
red_points = [tuple(map(int, input().split())) for i in range(N)]
blue_points = [tuple(map(int, input().split())) for i in range(N)]

red_points.sort(key=lambda x: - x[0] - x[1])
blue_points.sort(key=lambda x: x[0] + x[1])

count = 0

points_used = [False for i in range(N)]

for red in red_points:
    for i, blue in enumerate(blue_points):
        if not points_used[i] and red[0]< blue[0] and red[1] < blue[1]:
            count += 1
            points_used[i] = True
            break
            
print(count)

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))

blue = []
for i in range(N):
    c,d = map(int,input().split())
    blue.append((c,d,(c+1)*(d+1)))

blue = sorted(blue, key=lambda x:x[2])

ans = 0

for i in range(N):
    c = blue[i][0]
    d = blue[i][1]
#    print('c,d = ',c,d)

    ind = -1
    diff_min = N*N*N
    for j in range(N - ans):
#        print('red = ',red[j])
        a = red[j][0]
        b = red[j][1]

        if a < c and b < d:
            diff = (c - a)**2 + (d - b)**2
            if diff_min > diff:
                ind = j
                diff_min = diff

    if ind > -1:
        ans += 1
#        print('pop',c,d,red[ind])
        red.pop(ind)
#        print('remove',red)
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))

blue = []
for i in range(N):
    c,d = map(int,input().split())
    blue.append((c,d,(c+1)*(d+1)))

blue = sorted(blue, key=lambda x:x[2])

ans = 0

for i in range(N):
    c = blue[i][0]
    d = blue[i][1]
#    print('c,d = ',c,d)

    ind = -1
    diff_min = N*N*4
    for j in range(N - ans):
#        print('red = ',red[j])
        a = red[j][0]
        b = red[j][1]

        if a < c and b < d:
            diff = (c - a)**2 + (d - b)**2
            if diff_min > diff:
                ind = j
                diff_min = diff

    if ind > -1:
        ans += 1
#        print('pop',c,d,red[ind])
        red.pop(ind)
#        print('remove',red)
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
p_x=[0]*(2*N)
p_y=[0]*(2*N)
# N未満は赤い点
for i in range(N):
	x, y =map(int, input().split())
	p_x[x]=i
	p_y[y]=i
# N以上は青い点
for j in range(N):
	x, y =map(int, input().split())
	p_x[x]=N+j
	p_y[y]=N+j

pairs = 0
done_point=[]

for i in range(2*N-1, -1, -1):
	if p_x[i]<N:
		continue
	else:
		blue_x=i
		blue_y=p_y.index(p_x[i])
		#print(blue_x,blue_y)
		
		for j in range(blue_y-1, -1, -1):
			if p_y[j] < N:
				if p_x.index(p_y[j]) < blue_x:
					if p_y[j] not in done_point:
						done_point.append(p_y[j])
						pairs +=1
						#print(j, p_y.index(p_x[j]))
						#print("do it!")
						break
				else:
					continue

print(pairs)

Submission status: Wrong Answer

Solution code:
N=int(input())
p_x=[0]*(2*N)
p_y=[0]*(2*N)
# N未満は赤い点
for i in range(N):
	x, y =map(int, input().split())
	p_x[x]=i
	p_y[y]=i
# N以上は青い点
for j in range(N):
	x, y =map(int, input().split())
	p_x[x]=N+j
	p_y[y]=N+j

pairs = 0
done_point=[]

for i in range(2*N-1, -1, -1):
	if p_x[i]<N:
		continue
	else:
		blue_x=i
		blue_y=p_y.index(p_x[i])
		#print(blue_x,blue_y)
		
		for j in range(i-1, -1, -1):
			if p_x[j] < N:
				if p_y.index(p_x[j]) < blue_y:
					if p_x[j] not in done_point:
						done_point.append(p_x[j])
						pairs +=1
						#print(j, p_y.index(p_x[j]))
						#print("do it!")
						break
				else:
					continue

print(pairs)

Submission status: Wrong Answer

Solution code:
N = int(input())
s = [0]*N
l = [0]*N
for i in range(N):
    a, b = map(int, input().split())
    s[i] = (a, b)
 
for i in range(N):
    c, d = map(int, input().split())
    l[i] = (c, d)




V = N*2 # 頂点数
MAX_V = V
G = [0]*MAX_V # グラフの隣接リスト表現
for i in range(MAX_V):
    G[i] = []
match = [0]*MAX_V # マッチングのペア
used = [False]*MAX_V # DFSで既に調べたかのフラグ

# uとvを結ぶ辺をグラフに追加する
def addEdge(u, v):
    G[u].append(v)
    G[v].append(u)

##
for a in range(N):
    (rx, ry) = s[a]
    for b in range(N):
        (bx, by) = l[b]
        if rx < bx and ry < by:
            addEdge(a, b+(N-1))


# 増加パスをDFSで探す
def dfs(v):
    used[v] = True
    for i in range(len(G[v])):
        u = G[v][i]
        w = match[u]
        if w < 0 or (not used[w]) and dfs(w):
            match[v] = u
            match[u] = v
            return True
    return False

# 二部グラフの最大マッチングを求める
def bipartiteMatching():
    res = 0
    for i in range(len(match)):
        match[i] = -1
    for v in range(V):
        if match[v] < 0:
            for i in range(len(used)):
                used[i] = False
            if dfs(v):
                res += 1
    return res


#print(G)
#print(match)
print(bipartiteMatching())