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())
x = sorted([list(map(int, input().split())) for _ in range(N)], reverse=True)
y = sorted([list(map(int, input().split())) for _ in range(N)], reverse=True)

cnt = 0
idx = 0
for v in y:
  while idx < N and x[idx][0] >= v[0] and x[idx][1] >= v[1]:
    idx += 1
  if idx < N and x[idx][0] < v[0] and x[idx][1] < v[1]:
    cnt += 1
    idx += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
x = sorted([list(map(int, input().split())) for _ in range(N)], reverse=True)
y = sorted([list(map(int, input().split())) for _ in range(N)], reverse=True)

cnt = 0
idx = 0
for v in y:
  while idx < N and x[idx][0] >= v[0] and x[idx][1] >= v[1]:
    idx += 1
  if idx < N:
    cnt += 1
    idx += 1
  else:
    break
print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
x = sorted([list(map(int, input().split())) for _ in range(N)], reverse=True)
y = sorted([list(map(int, input().split())) for _ in range(N)], reverse=True)

i = 0
j = 0
cnt = 0
while j < N:
    if x[i][0] < y[j][0] and x[i][1] < y[j][1]:
        cnt += 1
        j += 1
        i = i + 1 if i < N - 1 else 0
        continue
    else:
	    i += 1
    if i == N:
      i = 0
      j += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
x = sorted([list(map(int, input().split())) for _ in range(N)], reverse=True)
y = sorted([list(map(int, input().split())) for _ in range(N)], reverse=True)

i = 0
j = 0
cnt = 0
while j < N:
    if x[i][0] < y[j][0] and x[i][1] < y[j][1]:
        cnt += 1
        i += 1
        j += 1
    else:
        i += 1
    if i == N:
      i = 0
      j += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
AB = [[0]+list(map(int,input().split())) for _ in range(n)]
CD = [list(map(int,input().split())) for _ in range(n)]
from operator import itemgetter

points = AB.copy()
for c,d in CD:
    points.append([1,c,max(0,d-0.1)])
points.sort(key = itemgetter(2))

ans = 0
record = [0]*(2*n+1)
for flag, x, y in points:
    if flag:
        for i in range(x):
            if record[i] > 0:
                ans += 1
                record[i] -= 1
                break
    else:
        record[x] += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
AB = [[0]+list(map(int,input().split())) for _ in range(n)]
CD = [list(map(int,input().split())) for _ in range(n)]
from operator import itemgetter
points = AB.copy()
for c,d in CD:
    points.append([1,c+0.1,d+0.1])
points.sort(key = itemgetter(1))
points.sort(key = itemgetter(2))

ans = 0
record = [0]*(2*n+1)
for flag, x, y in points:
    if flag:
        for i in range(int(x)):
            if record[i] > 0:
                ans += 1
                record[i] -= 1
                break
    else:
        record[x] += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
AB = [[0]+list(map(int,input().split())) for _ in range(n)]
CD = [list(map(int,input().split())) for _ in range(n)]
from operator import itemgetter
points = AB.copy()
for c,d in CD:
    points.append([1,c+0.1,d+0.1])
points.sort(key = itemgetter(1))
points.sort(key = itemgetter(2))

ans = 0
record = [0]*(2*n+1)
for flag, x, y in points:
    if flag:
        if 1 in record[:int(x)]:
            ans += 1
            record[record.index(1)] = 0
    else:
        record[x] += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
AB = [[0]+list(map(int,input().split())) for _ in range(n)]
CD = [list(map(int,input().split())) for _ in range(n)]
from operator import itemgetter
points = AB.copy()
for c,d in CD:
    points.append([1,c+0.1,d+0.1])
points.sort(key = itemgetter(2))
points.sort(key = itemgetter(1))
temp = 0
ans = 0
for flag, x, y in points:
    if flag:
        if temp > 0:
            ans += 1
            temp -= 1
    else:
        temp += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
AB = [[0]+list(map(int,input().split())) for _ in range(n)]
CD = [[1]+list(map(int,input().split())) for _ in range(n)]
from operator import itemgetter

points = AB+CD
points.sort(key = itemgetter(2))
points.sort(key = itemgetter(1))
temp = 0
ans = 0
for flag, x, y in points:
    if flag:
        if temp > 0:
            ans += 1
            temp -= 1
    else:
        temp += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
r,b = set(),set()
for i in range(n):
    rx,ry = map(int,input().split())
    r.add((rx,ry))
for i in range(n):
    bx,by = map(int,input().split())
    b.add((bx,by))
r = sorted(r)
b = sorted(b)
cnt = 0
for i in range(n):
    for N in range(len(b)):
        if r[i][0] < b[N][0] and r[i][1] < b[N][1]:
            cnt += 1
            del b[N]
            break
print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
AB = []
CD = []
for i in range(N):
  AB.append(tuple(map(int,input().split()))) 
for j in range(N):
  CD.append(tuple(map(int,input().split()))) 
num = 0
for i in range(len(AB)):
  for j in range(len(CD)):
    if AB[i][0] < CD[j][0] and AB[i][1] < CD[j][1]:
      AB[i] = (float('inf'),float('inf'))
      CD[j] = (float('-inf'),float('-inf'))
      num += 1
      break
print(num)

Submission status: Wrong Answer

Solution code:
#ABC091-C
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return list(input())
n=I()
R=[]
B=[]
for i in range(n):
    x,y=IL()
    R.append([x,y,x+y])
for i in range(n):
    x,y=IL()
    B.append([x,y,x+y])
R.sort(key=lambda x:-x[0])
B.sort(key=lambda x:x[0])
Rb=[True]*n
Bb=[True]*n

ans=0
for i in range(n):
    bx,by,bz=B[i]
    for j in range(n):
        rx,ry,rz=R[j]
        if rx<bx and ry<by and Rb[j] and Bb[i]:
            ans+=1
            Rb[j]=False
            Bb[i]=False
print(ans)

Submission status: Wrong Answer

Solution code:
#ABC091-C
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return list(input())
n=I()
R=[]
B=[]
for i in range(n):
    x,y=IL()
    R.append([x,y,x+y])
for i in range(n):
    x,y=IL()
    B.append([x,y,x+y])
R.sort(key=lambda x:-x[0])
B.sort(key=lambda x:x[0])
Rb=[True]*n
Bb=[True]*n

ans=0
for i in range(n):
    rx,ry,rz=R[i]
    for j in range(n):
        bx,by,bz=B[j]
        if rx<bx and ry<by and Rb[i] and Bb[j]:
            ans+=1
            Rb[i]=False
            Bb[j]=False
print(ans)

Submission status: Wrong Answer

Solution code:
#ABC091-C
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return list(input())
n=I()
R=[]
B=[]
for i in range(n):
    x,y=IL()
    R.append([x,y,x+y])
for i in range(n):
    x,y=IL()
    B.append([x,y,x+y])
R.sort(key=lambda x:-x[2])
B.sort(key=lambda x:x[2])
Rb=[True]*n
Bb=[True]*n

ans=0
for i in range(n):
    rx,ry,rz=R[i]
    for j in range(n):
        bx,by,bz=B[j]
        if rx<bx and ry<by and Rb[i] and Bb[j]:
            ans+=1
            Rb[i]=False
            Bb[j]=False
print(ans)

Submission status: Wrong Answer

Solution code:
#ABC091-C
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return list(input())
n=I()
R=[]
B=[]
for i in range(n):
    x,y=IL()
    R.append([x,y,x+y])
for i in range(n):
    x,y=IL()
    B.append([x,y,x+y])
R.sort(key=lambda x:-x[2])
B.sort(key=lambda x:x[2])
Rb=[True]*n
Bb=[True]*n
ans=0
for i in range(n):
    if not Rb[i]:
        continue
    rx,ry,rz=R[i]
    for j in range(n):
        if not Bb[j]:
            continue
        bx,by,bz=B[j]
        if rx<bx and ry<by and Rb[i] and Bb[j]:
            ans+=1
            Rb[i]=False
            Bb[j]=False
print(ans)

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[0],reverse=True)
cd.sort(key=lambda x:x[0],reverse=True)

idxa = 0
idxc = 0
cnt = 0
alist = []
while idxc < N:
    
    if ab[idxa][0] >= cd[idxc][0]:
        idxa += 1
    elif ab[idxa][1] >= cd[idxc][1]:
        idxa += 1
    else:
        if not(idxa in alist):
            cnt += 1
            idxa = 0
            idxc += 1
            alist += [idxa]
        else:
            idxa += 1
    if idxa == N:
        idxa = 0
        idxc += 1
    
    
print(cnt)

Submission status: Wrong Answer

Solution code:
def main():
    num = int(input())
    aka_data = [list(map(int, input().split())) for i in range(num)]
    ao_data = [list(map(int, input().split())) for i in range(num)]

    aka_data.sort(key=lambda x:(x[0],x[1]))
    ao_data.sort(key=lambda x: (-x[1], x[0]))

    ans = 0
    for j in range(num):
        for i in range(len(aka_data)):
            if aka_data[i][0] < ao_data[j][0] and aka_data[i][1] < ao_data[j][1]:
                aka_data.pop(i)
                ans += 1
                break

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:

def main():
    num = int(input())
    aka_data = [list(map(int, input().split())) for i in range(num)]
    ao_data = [list(map(int, input().split())) for i in range(num)]

    aka_data.sort(key=lambda x:(x[0],x[1]))
    ao_data.sort(key=lambda x: (x[0], x[1]))

    ans = 0
    for i in range(num):
        for j in range(len(ao_data)):
            if aka_data[i][0] < ao_data[j][0] and aka_data[i][1] < ao_data[j][1]:
                ao_data.pop(j)
                ans += 1
                break

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
red = [list(map(int, input().split())) for i in range(n)]
blue = [list(map(int, input().split())) for i in range(n)]
ans = 0
cups = []
for re in red:
    a, b = re
    cup = []
    for i, bu in enumerate(blue):
        c, d = bu
        if a < c and b < d:
            cup.append(i)
    cups.append(cup)
cups = sorted(cups, key=lambda x: len(x))
used = []
for cup in cups:
    for i in cup:
        if not i in used:
            ans += 1
            used.append(i)
            break
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
red = [list(map(int, input().split())) for i in range(n)]
blue = [list(map(int, input().split())) for i in range(n)]
ans = 0
cups = []
for re in red:
    a, b = re
    cup = []
    for i, bu in enumerate(blue):
        c, d = bu
        if a < c and b < d:
            cup.append(i)
    cups.append(cup)
cups = sorted(cups, key=lambda x: len(x))
for i in range(n):
    for j, cup in enumerate(cups):
        if i in cup:
            cups.pop(j)
            ans += 1
            break
print(ans)

Submission status: Wrong Answer

Solution code:

N = int(input())
A = [list(map(int, input().split())) for _ in range(N)]
B = [list(map(int, input().split())) for _ in range(N)]

A_sorted = sorted(A, key=lambda x: (x[0], x[1]))
B_sorted = sorted(B, key=lambda x: (x[0], x[1]))


def func():
    global A_sorted, B_sorted
    count = 0
    for b in B_sorted:
        a = None
        A_sorted_cp = A_sorted[:]
        while True:
            if len(A_sorted_cp) == 0:
                break
            a = A_sorted_cp.pop(0)
            if a[0] < b[0] and a[1]<b[1]:
                count += 1
                A_sorted.pop(A_sorted.index(a))
                break
    return count
            
    

print(func())

Submission status: Wrong Answer

Solution code:

N = int(input())
A = [list(map(int, input().split())) for _ in range(N)]
B = [list(map(int, input().split())) for _ in range(N)]

A_sorted = sorted(A, key=lambda x: (x[0], x[1]), reverse=True)
B_sorted = sorted(B, key=lambda x: (x[0], x[1]), reverse=True)

def func():
    global A_sorted, B_sorted
    count = 0
    for a in A_sorted:
        b = None
        B_sorted_cp = B_sorted[:]
        while True:
            if len(B_sorted_cp) == 0:
                break
            b = B_sorted_cp.pop(0)
            if a[0] < b[0] and a[1]<b[1]:
                count += 1
                B_sorted.pop(B_sorted.index(b))
                break
    return count
            
print(func())

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())

    reddots = [list(map(int, input().split())) for _ in range(N)]
    bluedots = [tuple(map(int, input().split())) for _ in range(N)]

    reddots = sorted(reddots, key=lambda x: x[0])
    bluedots = sorted(bluedots, key=lambda x: x[1], reverse=True)

    ans = 0
    for blue in bluedots:
        for red in reddots:
            if red[0] < blue[0] and red[1] < blue[1]:
                ans += 1
                red[0] = 201
                break

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())

    reddots = [list(map(int, input().split())) for _ in range(N)]
    bluedots = [tuple(map(int, input().split())) for _ in range(N)]

    reddots = sorted(reddots, key=lambda x: x[0])
    bluedots = sorted(bluedots, key=lambda x: x[1])

    ans = 0
    for blue in bluedots:
        for red in reddots:
            if red[0] < blue[0] and red[1] < blue[1]:
                ans += 1
                red[0] = 201
                break

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/snap/bin/pypy3


def main():
    N = int(input())

    reddots = [tuple(map(int, input().split())) for _ in range(N)]
    bluedots = [tuple(map(int, input().split())) for _ in range(N)]

    reddots = sorted(reddots, key=lambda x: x[0])

    ans = 0
    for reddot in reddots:
        satisfied_blues = [bluedot for bluedot in bluedots
                           if reddot[0] < bluedot[0] and
                           reddot[1] < bluedot[1]]
        if satisfied_blues:
            pair = min(satisfied_blues, key=lambda x: x[1])
            pair = min(
                (blue for blue in satisfied_blues if blue[1] <= pair[1]),
                key=lambda x: x[0])
            ans += 1
            bluedots.remove(pair)

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())

    reddots = [tuple(map(int, input().split())) for _ in range(N)]
    bluedots = [tuple(map(int, input().split())) for _ in range(N)]

    reddots = sorted(reddots, key=lambda x: x[0])

    ans = 0
    for reddot in reddots:
        satisfied_blues = [bluedot for bluedot in bluedots
                           if reddot[0] < bluedot[0] and
                           reddot[1] < bluedot[1]]
        if satisfied_blues:
            pair = min(satisfied_blues, key=lambda x: x[1])
            ans += 1
            bluedots.remove(pair)

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())

    reddots = [tuple(map(int, input().split())) for _ in range(N)]
    bluedots = [tuple(map(int, input().split())) for _ in range(N)]

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

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

    ans = 0
    for red_x, red_y in reddots:
        for blue_x, blue_y in bluedots:
            if red_x < blue_x and red_y < blue_y:
                ans += 1
                bluedots.remove((blue_x, blue_y))
                break

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())

    reddots = [tuple(map(int, input().split())) for _ in range(N)]
    bluedots = [tuple(map(int, input().split())) for _ in range(N)]

    reddots = sorted(reddots, key=lambda x: x[0])
    bluedots = sorted(bluedots, key=lambda x: x[1])

    ans = 0
    for red_x, red_y in reddots:
        for blue_x, blue_y in bluedots:
            if red_x < blue_x and red_y < blue_y:
                ans += 1
                bluedots.remove((blue_x, blue_y))
                break

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#入力
N = int(input())

red_x = []
red_y = []
for i in range(N):
    a = list(map(int, input().split()))
    red_x += [a]
    red_y += [a[::-1]]
red_x.sort(reverse = True)
red_y.sort(reverse = True)
#print (red_x, red_y)


blue_x = []
blue_y = []

for i in range(N):
    a = list(map(int, input().split()))
    blue_x += [a]
    blue_y += [a[::-1]]
blue_x.sort(reverse = True)
blue_y.sort(reverse = True)
#print (blue_x, blue_y)

def judge_x(m): #blue[m]がペアを作れるかどうかをTrue or Falseで返す x優先
    INF = 10 ** 9
    for i in range(N):
        if blue_x[m][0] > red_x[i][0]:
            if blue_x[m][1] > red_x[i][1]:
                red_x[i][0] = INF
                return True
        else:
            pass
    return False

def judge_y(m): #blue[m]がペアを作れるかどうかをTrue or Falseで返す y優先
    INF = 10 ** 9
    for i in range(N):
        if blue_y[m][1] > red_y[i][1]:
            if blue_y[m][0] > red_y[i][0]:
                red_y[i][1] = INF
                return True
        else:
            pass
    return False

count_x = 0
for s in range(N):
    if judge_x(s):
        count_x += 1
#print (count_x)

count_y = 0    
for t in range(N):
    if judge_y(t):
        count_y += 1
#print (count_y)

print (max(count_x, count_y))
#print (judge(0))
#print (judge(1))
#print (judge(2))
#print (judge(3))
#print (judge(4))

Submission status: Wrong Answer

Solution code:
#入力
N = int(input())

red_x = []
red_y = []
for i in range(N):
    a = list(map(int, input().split()))
    red_x += [a]
    red_y += [a[::-1]]
red_x.sort(reverse = True)
red_y.sort(reverse = True)
#print (red_x, red_y)


blue_x = []
blue_y = []

for i in range(N):
    a = list(map(int, input().split()))
    blue_x += [a]
    blue_y += [a[::-1]]
blue_x.sort(reverse = True)
blue_y.sort(reverse = True)
#print (blue_x, blue_y)

def judge_x(m): #blue[m]がペアを作れるかどうかをTrue or Falseで返す x優先
    INF = 10 ** 9
    for i in range(N):
        if blue_x[m][0] > red_x[i][0]:
            if blue_x[m][1] > red_x[i][1]:
                red_x[i][0] = INF
                return True
        else:
            pass
    return False

def judge_y(m): #blue[m]がペアを作れるかどうかをTrue or Falseで返す y優先
    INF = 10 ** 9
    for i in range(N):
        if blue_y[m][1] > red_y[i][1]:
            if blue_y[m][0] > red_y[i][0]:
                red_y[i][1] = INF
                return True
        else:
            pass
    return False

count_x = 0
for s in range(N):
    if judge_x(s):
        count_x += 1
#print (count_x)

count_y = 0    
for t in range(N):
    if judge_y(t):
        count_y += 1
#print (count_y)

print (min(count_x, count_y))
#print (judge(0))
#print (judge(1))
#print (judge(2))
#print (judge(3))
#print (judge(4))

Submission status: Wrong Answer

Solution code:
#入力
N = int(input())

red= []
for i in range(N):
    a = list(map(int, input().split()))
    red += [a]
red.sort(reverse = True)
#print (red)

blue= []
for i in range(N):
    a = list(map(int, input().split()))
    blue += [a]
blue.sort(reverse = True)
#print (blue)

def judge(m): #blue[m]がペアを作れるかどうかをTrue or Falseで返す
    INF = 10 ** 9
    for i in range(N):
        if blue[m][0] > red[i][0]:
            if blue[m][1] > red[i][1]:
                red[i][0] = INF
                return True
        else:
            pass
    return False

count = 0
for x in range(N):
    if judge(x):
        count += 1
print (count)
    
#print (judge(0))
#print (judge(1))
#print (judge(2))
#print (judge(3))
#print (judge(4))

Submission status: Wrong Answer

Solution code:
N = int(input())

INF = 10 ** 9
a = []
b = []
c = []
d = []

for i in range(N):
    x, y = map(int, input().split())
    a += [x]
    b += [y]

a.sort(reverse = True)
b.sort(reverse = True)
#print ('a= ', a)
#print ('b= ', b)

for j in range(N):
    v, w = map(int, input().split())
    c += [v]
    d += [w]

c.sort(reverse = True)
d.sort(reverse = True)
#print ('c= ', c)
#print ('d= ', d)

def judge(lst1, lst2): #lst1: 赤　lst2:青
    count = 0
    memo = -1
    for i in range(N):
        j = memo + 1
        while j < N:
#            print ('A')
#            print ('j= ', j)
            if lst2[i] > lst1[j]:
                lst1[j] = INF
                memo = j
                j = N
#                print ('lst1=', lst1)
                count += 1
#                print ('B')
            else:
#                print ('C')
                j += 1
                memo = j

    return count


#print ('x= ', judge(a, c))
#print ()
#print ('y= ', judge(b, d))
ans = min(judge(a, c), judge(b, d))
#print ('ans= ',ans)
print (ans)

Submission status: Wrong Answer

Solution code:


def read_input():
    n = int(input())

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

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

    return n, reds, blues


# 点rと点bの距離を返す、マッチング不可の場合は-1
def measure(r, b):
    if r[0] < b[0] and r[1] < b[1]:
        return (b[0] - r[0])**2 + (b[1] - r[1])**2
    return -1


def submit():
    n, reds, blues = read_input()

    red_point = {}
    for i, p in enumerate(reds):
        red_point[i] = p

    blue_point = {}
    for i, p in enumerate(blues):
        blue_point[i] = p

    dist_table = []
    for i in range(n):
        dist_table.append([-1] * n)

    dist_list = []
    for i in range(n):
        for j in range(n):
            r = red_point[i]
            b = blue_point[j]
            dist_table[i][j] = measure(r, b)
            if dist_table[i][j] > 0:
                dist_list.append((r, b, dist_table[i][j]))

    dist_list.sort(key=lambda x: x[2])

    red_matched = []
    blue_matched = []

    for d in dist_list:
        if d[0] not in red_matched and d[1] not in blue_matched:
            red_matched.append(d[0])
            blue_matched.append(d[1])

    print(len(red_matched))




if __name__ == '__main__':
    submit()

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())
ab = [list(map(int,input().split())) for _ in [0]*N]
cd = [list(map(int,input().split())) for _ in [0]*N]

data = np.zeros((2*N+1,2*N+1),dtype=int)
for a,b in ab:
    data[a+1:,b+1:] += 1
for i,tmp in enumerate(cd):
    c,d = tmp
    cd[i].append(data[c+1,d+1])

ans = 0
while cd != []:
    cd.sort(key = lambda x: x[2],reverse=True)
    c,d,score = cd[-1]
    if score <= 0:
        cd.pop()
        continue
    ans += 1
    #dataを更新
    for j in range(d+1,-1,-1):
        if data[c+1,j] == 0:
            j += 1
            break
    for i in range(c+1,-1,-1):
        if data[i,j] == 0:
            i += 1
            break
    data[i:,j:] -= 1
    #cdリストを更新
    cd.pop()
    for i,tmp in enumerate(cd):
        c,d,_ = tmp
        cd[i][2] = data[c+1,d+1]
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
	N = int(input())
	red = [[0, 0] for _ in range(N)]
	blue = [[0, 0] for _ in range(N)]
	for i in range(N):
		red[i] = list(map(int, input().split()))
	for i in range(N):
		blue[i] = list(map(int, input().split()))

	red.sort(key=lambda x: -x[0])
	blue.sort(key=lambda x: -x[0])

	ans = 0
	for b in blue:
		removes = []
		for i, r in enumerate(red):
			if r[0] < b[0] and r[1] < b[1]:
				removes.append([r[1], i])
		if len(removes) > 0:
			removes.sort(key=lambda x: -x[0])
			ans += 1
			red.pop(removes[0][1])

	print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
	N = int(input())
	red = [[0, 0] for _ in range(N)]
	blue = [[0, 0] for _ in range(N)]
	for i in range(N):
		red[i] = list(map(int, input().split()))
	for i in range(N):
		blue[i] = list(map(int, input().split()))

	red.sort(key=lambda x: -x[0]-x[1])
	blue.sort(key=lambda x: -x[0]-x[1])

	ans = 0
	for r in red:
		comp = []
		for i, b in enumerate(blue):
			if r[0] < b[0] and r[1] < b[1]:
				comp.append([b[0], b[1], i])
		if len(comp) > 0:
			comp.sort(key=lambda x: -x[0]-x[1])
			ans += 1
			blue.pop(comp[0][2])
	print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
	N = int(input())
	red = [[0, 0] for _ in range(N)]
	blue = [[0, 0] for _ in range(N)]
	for i in range(N):
		red[i] = list(map(int, input().split()))
	for i in range(N):
		blue[i] = list(map(int, input().split()))

	red.sort(key=lambda x: -x[0]-x[1])
	blue.sort(key=lambda x: -x[0]-x[1])

	ans = 0
	for r in red:
		comp = []
		for i, b in enumerate(blue):
			if r[0] < b[0] and r[1] < b[1]:
				comp.append([b[1], i])
		if len(comp) > 0:
			comp.sort(key=lambda x: -x[0])
			ans += 1
			blue.pop(comp[0][1])
	print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
ab = [[int(i) for i in input().split(" ")] for _ in range(N)]
cd = [[int(i) for i in input().split(" ")] for _ in range(N)]
ab_sort = sorted(ab, key=lambda x:-x[1])
cd_sort = sorted(cd, key=lambda x:x[0])
print(ab_sort)
print(cd_sort)
cnt = 0
for c, d in cd_sort:
    for a, b in ab_sort:
        if a < c and b < d:
            ab_sort.remove([a, b])
            cnt += 1
            break

print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
ab = [[int(i) for i in input().split(" ")] for _ in range(N)]
cd = [[int(i) for i in input().split(" ")] for _ in range(N)]
ab_sort = sorted(ab, key=lambda x:(-x[0], -x[1]))
cd_sort = sorted(cd, key=lambda x:(-x[0], -x[1]))

cnt = 0
for c, d in cd_sort:
    for a, b in ab_sort:
        if a < c and b < d:
            ab_sort.remove([a, b])
            cnt += 1
            break
print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
ab = [[int(i) for i in input().split(" ")] for _ in range(N)]
cd = [[int(i) for i in input().split(" ")] for _ in range(N)]
ab_sort = sorted(ab, key=lambda x:(-x[0], -x[1]))
cd_sort = sorted(cd, key=lambda x:(-x[0], -x[1]))

cnt = 0
for c, d in cd_sort:
    for a, b in ab_sort:
        if a < c and b < d:
            ab_sort.remove([a, b])
            cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
red = []
blue = []
for i in range(n):
  rx, ry = map(int, input().split())
  red.append((rx, ry))
for i in range(n):
  bx, by = map(int, input().split())
  blue.append((bx, by))

ans = []
for r in red:
  for b in blue:
    if r[0]<b[0] and r[1]<b[1]:
      ans.append(b)
print(len(set(ans)))

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())
ab = [list(map(int,input().split())) for _ in [0]*N]
cd = [list(map(int,input().split())) for _ in [0]*N]

data = np.zeros((2*N+1,2*N+1),dtype=int)
for a,b in ab:
    data[a+1:,b+1:] += 1
for i,tmp in enumerate(cd):
    c,d = tmp
    cd[i].append(data[c+1,d+1])

ans = 0
while cd != []:
    cd.sort(key = lambda x: x[2],reverse=True)
    c,d,score = cd[-1]
    if score <= 0:
        cd.pop()
        continue
    ans += 1
    #dataを更新
    for i in range(c+1,-1,-1):
        if data[i,d+1] == 0:
            i += 1
            break
    for j in range(d+1,-1,-1):
        if data[i,j] == 0:
            j += 1
            break
    data[i:,j:] -= 1
    #cdリストを更新
    cd.pop()
    for i,tmp in enumerate(cd):
        c,d,_ = tmp
        cd[i][2] = data[c+1,d+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
for i in range(N*2):
    counter = -1
    min=0
    for j in range(0,i):
        if cxy_sort[i][0] == "b" and cxy_sort[j][0] == "r" and cxy_sort[j][3] == 0:
            if cxy_sort[j][2] >= min:
                min = cxy_sort[j][2]
                counter = j
    if counter != -1:
        cxy_sort[counter][3] = 1
        cnt += 1

print(cnt)

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
for i in range(N*2):
    counter = -1
    for j in range(0,i):
        if cxy_sort[i][0] == "b" and cxy_sort[j][0] == "r" and cxy_sort[j][3] == 0:
            counter = j

    if counter != -1:
        cxy_sort[counter][3] = 1
        cnt += 1

print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())

R = [()] * N
B = [()] * N

for i in range(N):
    a, b = map(int, input().split())
    R[i] = (a,b)

for i in range(N):
    a, b = map(int, input().split())
    B[i] = (a, b)

B = sorted(B)
R = sorted(R)

ans = 0
for a, b in B:
    d = -1
    mem = -1
    for i in range(len(R)):
        if R[i][0] < a and R[i][1] < b:
            if mem <= R[i][1]:
                d = i
    if d != -1:
        R.pop(d)
        ans += 1


print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

R = [()] * N
B = [()] * N

for i in range(N):
    a, b = map(int, input().split())
    R[i] = (a,b)

for i in range(N):
    a, b = map(int, input().split())
    B[i] = (a, b)

B = sorted(B)

ans = 0
for a, b in B:
    d = -1
    mem = -1
    for i in range(len(R)):
        if R[i][0] < a and R[i][1] < b:
            if mem <= R[i][1]:
                d = i
    if d != -1:
        R.pop(d)
        ans += 1

print(ans)