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())
red = [tuple(map(int, input().split())) for i in range(n)]
blue = [tuple(map(int, input().split())) for i in range(n)]
blue = sorted(blue)

INF = 1000000000
min_dif = INF
min_index = -1
pair = 0

while len(blue):
    min_dif = INF
    min_index = -1
    for i in range(len(red)):
        if blue[0][0] > red[i][0] and blue[0][1] > red[i][1]:
            dif = blue[0][0] + blue[0][1] - red[i][0] - red[i][1]
            if dif < min_dif:
                min_dif = dif
                min_index = i
    blue.pop(0)
    if min_index != -1:
        red.pop(min_index)
        pair += 1


print(pair)

Submission status: Wrong Answer

Solution code:
n = int(input())
red = [tuple(map(int, input().split())) for i in range(n)]
blue = [tuple(map(int, input().split())) for i in range(n)]

INF = 1000000000
min_dif = INF
min_index = -1
pair = 0

while len(blue):
    min_dif = INF
    min_index = -1
    for i in range(len(red)):
        if blue[0][0] > red[i][0] and blue[0][1] > red[i][1]:
            dif = blue[0][0] + blue[0][1] - red[i][0] - red[i][1]
            if dif < min_dif:
                min_dif = dif
                min_index = i
    blue.pop(0)
    if min_index != -1:
        red.pop(min_index)
        pair += 1

print(pair)

Submission status: Wrong Answer

Solution code:
n = int(input())
red = [tuple(map(int, input().split())) for i in range(n)]
blue = [tuple(map(int, input().split())) for i in range(n)]

INF = 1000000000
min_dif = INF
min_index = -1
pair = 0

while len(blue):
    min_dif = INF
    min_index = -1
    for i in range(len(red)):
        if blue[0][0] > red[i][0] and blue[0][1] > red[i][1]:
            dif = blue[0][0] * blue[0][1] - red[i][0] * red[i][1]
            if dif < min_dif:
                min_dif = dif
                min_index = i
    blue.pop(0)
    if min_index != -1:
        red.pop(min_index)
        pair += 1

print(pair)

Submission status: Wrong Answer

Solution code:
n = int(input())
red = [tuple(map(int, input().split())) for i in range(n)]
blue = [tuple(map(int, input().split())) for i in range(n)]

INF = 1000000000
min_dif = INF
min_index = -1
pair = 0

while len(red):
    min_dif = INF
    min_index = -1
    for i in range(len(blue)):
        if blue[i][0] > red[0][0] and blue[i][1] > red[0][1]:
            dif = blue[i][0] * blue[i][1] - red[0][0] * red[0][1]
            if dif < min_dif:
                min_dif = dif
                min_index = i
    red.pop(0)
    if min_index != -1:
        blue.pop(min_index)
        pair += 1

print(pair)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = [tuple(map(int, input().split())) for _ in range(N)]
b = [tuple(map(int, input().split())) for _ in range(N)]
c = [0 for _ in range(N)]
a.sort(key=lambda x:-(x[0]+x[1]))
b.sort(key=lambda x:-(x[0]+x[1]))
cnt = 0
for an in a:
  diff = 200
  pos = 0
  pair = False
  for i, bn in enumerate(b):
    if c[i] == 0 and bn[0] > an[0] and bn[1] > an[1]:
      pair = True
      temp = min(abs(bn[0]-an[0]), abs(bn[1]-an[1]))
      if temp < diff:
        pos = i
        diff = temp
  if pair:
    c[pos] = 1
    cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = [tuple(map(int, input().split())) for _ in range(N)]
b = [tuple(map(int, input().split())) for _ in range(N)]
c = [0 for _ in range(N)]
a.sort(key=lambda x:-(x[0]+x[1]))
cnt = 0
for an in a:
  diff = 200
  pos = 0
  pair = False
  for i, bn in enumerate(b):
    if c[i] == 0 and bn[0] > an[0] and bn[1] > an[1]:
      pair = True
      temp = min(abs(bn[0]-an[0]), abs(bn[1]-an[1]))
      if temp < diff:
        pos = i
        diff = temp
  if pair:
    c[pos] = 1
    cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
import sys
from statistics import *
from collections import *
from operator import itemgetter
stdin = sys.stdin

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

n = ni()
red = []
blue = []
for i in range(n):
    li = na()
    li.append(0)
    red.append(li)
for i in range(n):
    li = na()
    li.append(0)
    blue.append(li)
red = sorted(red, key=itemgetter(0))
blue = sorted(blue, key=itemgetter(0))
ct = 0
for i in range(n):
    a, b, r = red[i]
    for j in range(n):
        c, d, l = blue[j]
        if r == 0 and l == 0 and a < c and b < d:
            ct += 1
            red[i][2] = 1
            blue[j][2] = 1
            break
print(ct)

Submission status: Wrong Answer

Solution code:
N = int(input())
ABs = []
for i in range(N):
  a, b = map(int, input().split())
  ABs.append((a, b))
CDs = []
for i in range(N):
  c, d = map(int, input().split())
  CDs.append((c, d))
Ds = [set() for i in range(N)]
for i in range(N):
  a, b = ABs[i]
  for j in range(N):
    c, d = CDs[j]
    if a < c and b < d:
      Ds[i].add(j)
print(Ds)

Submission status: Wrong Answer

Solution code:
n = int(input())
r = [] 
b = [] 
flag = [True] * n
ans = 0
for i in range(n):
    x,y = map(int,input().split())
    r.append([x,y])
for i in range(n):
    x,y = map(int,input().split())
    b.append([x,y])
sorted(b)

for i in range(n):
    max_y = -1
    tmp = -1
    for j in range(n):
        if b[i][0] > r[j][0] and b[i][1] > r[j][1] and r[j][1] > max_y and flag[j] == True:
            tmp = j
            max_y = r[j][1]
    if tmp != -1:
        ans += 1
        flag[tmp] = False
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)]
a1 = sorted(a, key = lambda x:x[0])
b1 = sorted(b, key = lambda x:x[0])

inum = []
for j in range(n):
    bench = []
    for i in range(n):
        if a1[i] not in inum:
            if a1[i][0]< b1[j][0] and a1[i][1]< b1[j][1]:
                bench.append(a1[i])
    if bench:
        inum.append(max(bench))
print(len(inum))

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)]
a1 = sorted(a, key = lambda x:x[1], reverse=True)
b1 = sorted(b, key = lambda x:x[1], reverse=True)
a2 = sorted(a1, key = lambda x:x[0])
b2 = sorted(b1, key = lambda x:x[0])

inum = []
jnum = []
for j in range(n):
    for i in range(n):
        if i not in inum and j not in jnum:
            if a2[i][0]< b2[j][0] and a2[i][1]< b2[j][1]:
                inum.append(i)
                jnum.append(j)

print(len(jnum))

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)]
a1 = sorted(a, key = lambda x:x[1], reverse=True)
b1 = sorted(b, key = lambda x:x[1], reverse=True)
a2 = sorted(a1, key = lambda x:x[0])
b2 = sorted(b1, key = lambda x:x[0])

inum = []
jnum = []
for i in range(n):
    for j in range(n):
        if i not in inum and j not in jnum:
            if a2[i][0]< b2[j][0] and a2[i][1]< b2[j][1]:
                inum.append(i)
                jnum.append(j)

print(len(jnum))

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)]
a1 = sorted(a, key = lambda x:x[1], reverse=True)
b1 = sorted(b, key = lambda x:x[1], reverse=True)
a2 = sorted(a1, key = lambda x:x[0])
b2 = sorted(b1, key = lambda x:x[0])

inum = []
jnum = []
for i in range(n):
    for j in range(n):
        if i not in inum and j not in jnum:
            if a1[i][0]< b1[j][0] and a1[i][1]< b1[j][1]:
                inum.append(i)
                jnum.append(j)

print(len(jnum))

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)]
aa = sorted(a, key = lambda x:x[0])
bb = sorted(b, key = lambda x:x[0])
aaa = sorted(a, key = lambda x:x[1])
bbb = sorted(b, key = lambda x:x[1])
aaaa = sorted(a, key = lambda x:x[0], reverse=True)
bbbb = sorted(b, key = lambda x:x[0], reverse= True)
aaaaa = sorted(a, key = lambda x:x[1], reverse=True)
bbbbb = sorted(b, key = lambda x:x[1], reverse= True)


inum = []
jnum = []
iinum = []
jjnum = []
iiinum = []
jjjnum = []
iiiinum = []
jjjjnum = []
for i in range(n):
    for j in range(n):
        if i not in inum and j not in jnum:
            if aa[i][0]< bb[j][0] and aa[i][1]< bb[j][1]:
                inum.append(i)
                jnum.append(j)
        if i not in iinum and j not in jjnum:
            if aaa[i][0]< bbb[j][0] and aaa[i][1]< bbb[j][1]:
                iinum.append(i)
                jjnum.append(j)
        if i not in iiinum and j not in jjjnum:
            if aaaa[i][0]< bbbb[j][0] and aaaa[i][1]< bbbb[j][1]:
                iiinum.append(i)
                jjjnum.append(j)
        if i not in iiiinum and j not in jjjjnum:
            if aaaaa[i][0]< bbbbb[j][0] and aaaaa[i][1]< bbbbb[j][1]:
                iiiinum.append(i)
                jjjjnum.append(j)

print(max(len(jnum), len(jjnum), len(jjjnum), len(jjjjnum)))

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)]
aa = sorted(a, key = lambda x:x[0])
bb = sorted(b, key = lambda x:x[0])
aaa = sorted(a, key = lambda x:x[1])
bbb = sorted(b, key = lambda x:x[1])

inum = []
jnum = []
iinum = []
jjnum = []
iiinum = []
jjjnum = []
iiiinum = []
jjjjnum = []
for i in range(n):
    for j in range(n):
        if i not in inum and j not in jnum:
            if aa[i][0]< bb[j][0] and aa[i][1]< bb[j][1]:
                inum.append(i)
                jnum.append(j)
        if i not in iinum and j not in jjnum:
            if aaa[i][0]< bbb[j][0] and aaa[i][1]< bbb[j][1]:
                iinum.append(i)
                jjnum.append(j)
        if i not in iiinum and j not in jjjnum:
            if aaa[i][0]< bb[j][0] and aaa[i][1]< bb[j][1]:
                iiinum.append(i)
                jjjnum.append(j)
        if i not in iiiinum and j not in jjjjnum:
            if aa[i][0]< bbb[j][0] and aa[i][1]< bbb[j][1]:
                iiiinum.append(i)
                jjjjnum.append(j)

print(max(len(jnum), len(jjnum), len(jjjnum), len(jjjjnum)))

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)]
aa = sorted(a, key = lambda x:x[0])
bb = sorted(b, key = lambda x:x[0])
aaa = sorted(a, key = lambda x:x[1])
bbb = sorted(b, key = lambda x:x[1])

jnum = []
for i in range(n):
    for j in range(n):
        if j not in jnum:
            if aa[i][0]< bb[j][0] and aa[i][1]< bb[j][1]:
                jnum.append(j)
                break

jjnum = []
for ii in range(n):
    for jj in range(n):
        if jj not in jjnum:
            if aaa[ii][0]< bbb[jj][0] and aaa[ii][1]< bbb[jj][1]:
                jjnum.append(jj)
                break
print(max(len(jnum), len(jjnum)))

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)]
aa = sorted(a, key = lambda x:x[0])
bb = sorted(b, key = lambda x:x[0])
aaa = sorted(a, key = lambda x:x[1])
bbb = sorted(b, key = lambda x:x[1])

inum= []
jnum = []
for i in range(n):
    for j in range(n):
        if i not in inum and j not in jnum:
            if aa[i][0]< bb[j][0] and aa[i][1]< bb[j][1]:
                inum.append(i)
                jnum.append(j)

iinum= []
jjnum = []
for ii in range(n):
    for jj in range(n):
        if ii not in iinum and jj not in jjnum:
            if aaa[ii][0]< bbb[jj][0] and aaa[ii][1]< bbb[jj][1]:
                iinum.append(ii)
                jjnum.append(jj)
print(max(len(inum), len(iinum)))

Submission status: Wrong Answer

Solution code:
N = int(input())
red_ps  = []
blue_ps = []
for i in range(N):
    red_p =list((map(int,input().split())))
    red_p.append(red_p[0]+red_p[1])
    red_ps.append(red_p)
for i in range(N):
    blue_p =list((map(int,input().split())))
    blue_p.append(blue_p[0]+blue_p[1])
    blue_ps.append(blue_p)

#print(red_ps)
#print(blue_ps)

count = 0
for i in range(4*N-2,-1,-1):
    for r_p in red_ps:
        if r_p[2] == i:
#            print(r_p,i)
            a = 0
            for k in range(i+1,4*N-1):
#                print('check',k)
                for l,b_p in enumerate(blue_ps):
#                    print('aaa')
                    if b_p[2] == k and b_p[0] > r_p[0] and b_p[1] > r_p[1]:
                        count += 1
                        a = blue_ps.pop(l)
#                        print(a)
                        break
                if a != 0:
                    break

print(count)

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    red, blue = [], []
    for _ in range(N):
        a, b = map(int, input().split())
        red.append([a, b])
    for _ in range(N):
        a, b = map(int, input().split())
        blue.append([a, b])

    d = dict()
    for i in range(N):
        for j in range(N):
            if blue[i][0] > red[j][0] and blue[i][1] > red[j][1]:
                if i not in d:
                    d[i] = [j]
                else:
                    d[i].append(j)
    lv = sorted(d.values(), key = lambda x: len(x))
    used = set()
    while lv:
        v = lv[0][0]
        used.add(v)
        temp = []
        for ls in lv[1:]:
            if v in ls:
                ls.remove(v)
            if len(ls) > 0:
                temp.append(ls)
        lv = temp
        lv = sorted(lv, key = lambda x: len(x))
    return len(used)

if __name__ == '__main__':
    print(main())

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    red, blue = [], []
    for _ in range(N):
        a, b = map(int, input().split())
        red.append([a, b])
    for _ in range(N):
        a, b = map(int, input().split())
        blue.append([a, b])

    d = dict()
    for i in range(N):
        for j in range(N):
            if blue[i][0] > red[j][0] and blue[i][1] > red[j][1]:
                if i not in d:
                    d[i] = [j]
                else:
                    d[i].append(j)
    lv = sorted(d.values(), key = lambda x: len(x))
    used = set()
    while lv:
        v = lv[0][0]
        used.add(v)
        temp = []
        for ls in lv[1:]:
            if v in ls:
                ls.remove(v)
            if len(ls) > 0:
                temp.append(ls)
        lv = temp
    return len(used)

if __name__ == '__main__':
    print(main())

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    red, blue = [], []
    for _ in range(N):
        a, b = map(int, input().split())
        red.append([a, b])
    for _ in range(N):
        a, b = map(int, input().split())
        blue.append([a, b])

    d = dict()
    for i in range(N):
        for j in range(N):
            if blue[i][0] > red[j][0] and blue[i][1] > red[j][1]:
                if i not in d:
                    d[i] = [j]
                else:
                    d[i].append(j)
    lv = sorted(d.values(), key = lambda x: len(x))
    used = set()
    while lv:
        v = lv[0][0]
        used.add(v)
        temp = []
        for ls in lv[1:]:
            if v in ls:
                ls.remove(v)
            if len(ls) > 0:
                temp.append(ls)
        lv = temp
    return len(used)

Submission status: Wrong Answer

Solution code:
N = int(input())
R = [list(map(int,input().split())) for _ in range(N)]
R = sorted(R,key=lambda x:x[0]+x[1])[::-1] ##赤い大きいものから処理していく。
#print(R)
B = [list(map(int,input().split())) for _ in range(N)]

ans = 0
while(len(R)!=0):
    red = R.pop(0)
    ok = [i if B[i][0]>red[0] and B[i][1]>red[1] else -1 for i in range(len(B))]
    ##↑ここではこの赤よりも大きいBを探してくいく。
    mind = 100000000000
    wj = 0
    #print(ok)
    if sum(ok) == (-1*len(B)):
        continue
        ##全部-1ならそいつはもうだめだ
    ans+=1
    
    for j in range(len(B)):
        if ok[j] != -1:
            ##　-1じゃないやつの中で一番近いものを使っていく。
            if B[ok[j]][0]-red[0] + B[ok[j]][1]-red[1] < mind:
                mind = B[ok[j]][0]-red[0] + B[ok[j]][1]-red[1]
                wj = j
    B.pop(wj)            
    #print('これは青いやつ{}'.format(B.pop(wj)))
    #print('これは赤いやつ{}'.format(red))
    
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = []
B = []
for i in range(N):
  a, b = map(int, input().split())
  A.append([a, b])
for i in range(N):
  a, b = map(int, input().split())
  B.append([a, b])
A = sorted(A, key=lambda x: (x[1]))
B = sorted(B, key=lambda x: (x[0]))
count = 0
for i in range(len(B)):
  for j in range(len(A) - 1, -1, -1):
    if A[j][0] < B[i][0] and A[j][1] < B[i][1]:
      print(A[j], B[i])
      A = A[:j] + A[j+1:]
      count += 1
      break
print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = []
B = []
for i in range(N):
  a, b = map(int, input().split())
  A.append([a, b])
for i in range(N):
  a, b = map(int, input().split())
  B.append([a, b])
A = sorted(A, key=lambda x: (x[1]))
B = sorted(B, key=lambda x: (x[0]))
count = 0
for i in range(len(B) - 1, -1 ,-1):
  for j in range(len(A) - 1, -1, -1):
    if A[j][0] < B[i][0] and A[j][1] < B[i][1]:
      A = A[:j] + A[j+1:]
      count += 1
      break
print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = []
B = []
for i in range(N):
  a, b = map(int, input().split())
  A.append([a, b])
for i in range(N):
  a, b = map(int, input().split())
  B.append([a, b])
A = sorted(A, key=lambda x: (x[0], x[1]))
B = sorted(B, key=lambda x: (x[0], x[1]))
count = 0
for i in range(len(B) - 1, -1 ,-1):
  for j in range(len(A) - 1, -1, -1):
    if A[j][0] < B[i][0] and A[j][1] < B[i][1]:
      A = A[:j] + A[j+1:]
      count += 1
      break
print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = []
B = []
for i in range(N):
  a, b = map(int, input().split())
  A.append([a, b])
for i in range(N):
  a, b = map(int, input().split())
  B.append([a, b])
A = sorted(A, key=lambda x: (x[0], x[1]))
B = sorted(B, key=lambda x: (x[0], x[1]))
count = 0
for i in range(len(B) - 1, -1 ,-1):
  for j in range(len(A) - 1, -1, -1):
    if A[j][0] < B[i][0] and A[j][1] < B[i][1]:
      A.pop()
      count += 1
      break
    else:
      A.pop()
print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
R = [list(map(int,input().split())) for _ in range(N)]
B = [list(map(int,input().split())) for _ in range(N)]
B = sorted(B,key=lambda x:x[0]+x[1])

ans = 0
while(len(B)!=0):
    blue = B.pop(0)
    ok = [i if R[i][0]<blue[0] and R[i][1]<blue[1] else -1 for i in range(len(R))]
    mind = 100000000000
    wj = 0
    if sum(ok) == (-1*len(R)):
        continue
    ans+=1
    for j in range(len(R)):
        if ok[j] != -1:
            if blue[0]-R[ok[j]][0] + blue[1]-R[ok[j]][1] < mind:
                mind = blue[0]-R[ok[j]][0] + blue[1]-R[ok[j]][1]
                wj = j
    R.pop(wj)
    
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
R = [list(map(int,input().split())) for _ in range(N)]
B = [list(map(int,input().split())) for _ in range(N)]
B = sorted(B,key=lambda x:x[0]+x[1])

ans = 0
while(len(B)!=0):
    blue = B.pop(0)
    ok = [i if R[i][0]<blue[0] and R[i][1]<blue[1] else -1 for i in range(len(R))]
    mind = 100000000000
    wj = 0
    if sum(ok) == (-1*len(R)):
        continue
    ans+=1
    for j in range(len(R)):
        if ok[j] != -1:
            if blue[0]-R[ok[j]][0] + blue[1]-R[ok[j]][1] < mind:
                mind = blue[0]-R[ok[j]][0] + blue[0]-R[ok[j]][0]
                wj = j
    R.pop(wj)
    
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
red = [tuple(map(int, input().split())) for _ in range(N)]
blue = [tuple(map(int, input().split())) for _ in range(N)]
checked = [0] * (N)
red.sort()
ans = 0
for star in red:
  min_dis = 10**6
  min_idx = 0
  for i in range(N):
    if star[0] < blue[i][0] and star[1] < blue[i][1] and checked[i] == 0:
      dis = min(blue[i][0]-star[0], blue[i][1]-star[1])
      if dis < min_dis:
        min_idx = i
        min_dis = dis
  if min_dis != 10**6:
    checked[min_idx] = 1
    ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

AB = [[int(_) for _ in input().split()] for i in range(N)]
CD = [[int(_) for _ in input().split()] + [0, ] for i in range(N)]
AB.sort(reverse=True)
CD.sort(reverse=True)
ans = 0
for a, b in AB:
    # for c, d, f in CD:
    min_idx = -1
    min_val = 1e10

    for i in range(N):
        c, d, f = CD[i]
        if f: continue
        if c <= a and d <= b: break
        if min_val > d:
            min_val = d
            min_idx = i
    if min_idx >= 0:
        ans += 1
        CD[min_idx][2] = 1
        # print('pare:', (a, b), CD[min_idx])
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
ab=[list(input().split()) for _ in range(n)]
cd=[list(input().split()) for _ in range(n)]
ab.sort(key=lambda x:(x[1],x[0]),reverse=True)
cd.sort()

ans=0
for i in range(len(cd)):
  for j in range(len(ab)):
    c,d=cd[i]
    a,b=ab[j]
  
    if int(a)<int(c) and int(b)<int(d):
      ans+=1
      ab.pop(j)
      break
    
print(ans)

Submission status: Wrong Answer

Solution code:
import heapq

n = int(input())
ab = [[int(i) for i in input().split()] for j in range(n)]
cd = [[int(i) for i in input().split()] for j in range(n)]

ab.sort(reverse=True)
cd.sort(reverse=True)

#print(ab,cd)

hq = []
tmp = 0
ans = 0

for i in range(n):
    while tmp <= n-1 and ab[i][0] < cd[tmp][0]:
        hq.append(cd[tmp][1])
        hq.sort(reverse=True)
        tmp += 1
    #print(hq)
    if len(hq) > 0:
        for j in range(len(hq)):
            if hq[j] > ab[i][1]:
                del hq[j]
                ans += 1
                break
            elif hq[j] <= ab[i][1]:
                break
            else:
                continue
        
print(ans)

Submission status: Wrong Answer

Solution code:
import heapq

n = int(input())
ab = [[int(i) for i in input().split()] for j in range(n)]
cd = [[int(i) for i in input().split()] for j in range(n)]

ab.sort(reverse=True)
cd.sort(reverse=True)

#print(ab,cd)

hq = []
tmp = 0
ans = 0

for i in range(n):
    while tmp <= n-1 and ab[i][0] < cd[tmp][0]:
        heapq.heappush(hq,cd[tmp][1])
        tmp += 1
    #print(hq)
    if len(hq) > 0:
        for j in range(len(hq)):
            if hq[j] > ab[i][1]:
                del hq[j]
                ans += 1
                break
            """
            elif hq[j] <= ab[i][1]:
                break
            else:
                continue
            """
        
print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin
N = int(stdin.readline().rstrip())
A = [0] * N
B = [0] * N

for i in range(N):
    a,b = [int(x) for x in stdin.readline().rstrip().split()]
    A[i] = (a,b)

for j in range(N):
    a,b = [int(x) for x in stdin.readline().rstrip().split()]
    B[j] = (a,b)

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

ans = 0
for k in B:
    for l in A:
        if l[0] < k[0] and l[1] < k[1]:
            ans += 1
            A.remove(l)
            break
print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin
N = int(stdin.readline().rstrip())
A = [0] * N
B = [0] * N

for i in range(N):
    a,b = [int(x) for x in stdin.readline().rstrip().split()]
    A[i] = (a,b)

for j in range(N):
    a,b = [int(x) for x in stdin.readline().rstrip().split()]
    B[j] = (a,b)

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

ans = 0
for k in A:
    for l in B:
        if k[0] < l[0] and k[1] < l[1]:
            ans += 1
            B.remove(l)
            break
print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin
N = int(stdin.readline().rstrip())
A = [0] * N
B = [0] * N

for i in range(N):
    a,b = [int(x) for x in stdin.readline().rstrip().split()]
    A[i] = (a,b)

for j in range(N):
    a,b = [int(x) for x in stdin.readline().rstrip().split()]
    B[j] = (a,b)

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

ans = 0
for k in A:
    for l in B:
        if k[0] < l[0] and k[1] < l[1]:
            ans += 1
            B.remove(l)
            break
print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin
N = int(stdin.readline().rstrip())
A = [0] * N
B = [0] * N

for i in range(N):
    a,b = [int(x) for x in stdin.readline().rstrip().split()]
    A[i] = (a,b)

for j in range(N):
    a,b = [int(x) for x in stdin.readline().rstrip().split()]
    B[j] = (a,b)

A = sorted(A,key=lambda x:x[1],reverse=True)

ans = 0
for k in A:
    for l in B:
        if k[0] < l[0] and k[1] < l[1]:
            ans += 1
            B.remove(l)
            break
print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin
N = int(stdin.readline().rstrip())
A = [0] * N
B = [0] * N

for i in range(N):
    a,b = [int(x) for x in stdin.readline().rstrip().split()]
    A[i] = (a,b)

for j in range(N):
    a,b = [int(x) for x in stdin.readline().rstrip().split()]
    B[j] = (a,b)

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

ans = 0
for k in A:
    for l in B:
        if k[0] < l[0] and k[1] < l[1]:
            ans += 1
            B.remove(l)
            break
print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin
N = int(stdin.readline().rstrip())
A = [0] * N
B = [0] * N

for i in range(N):
    a,b = [int(x) for x in stdin.readline().rstrip().split()]
    A[i] = (a,b)

for j in range(N):
    a,b = [int(x) for x in stdin.readline().rstrip().split()]
    B[j] = (a,b)

B = sorted(B,key=lambda x:x[1],reverse=True)

ans = 0
for k in A:
    for l in B:
        if k[0] < l[0] and k[1] < l[1]:
            ans += 1
            B.remove(l)
            break
print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin
N = int(stdin.readline().rstrip())
A = [0] * N
B = [0] * N

for i in range(N):
    a,b = [int(x) for x in stdin.readline().rstrip().split()]
    A[i] = (a,b)

for j in range(N):
    a,b = [int(x) for x in stdin.readline().rstrip().split()]
    B[j] = (a,b)

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

ans = 0
for k in A:
    for l in B:
        if k[0] < l[0] and k[1] < l[1]:
            ans += 1
            B.remove(l)
            break
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 = sorted(ab, key=lambda x:x[1])
cd.sort()
print(ab)
print(cd)
  
count = 0
for i in range(N):
  idx = -1
  for j in range(len(ab)):
    if cd[i][0] > ab[j][0] and cd[i][1] > ab[j][1]:
      idx = j
  if idx >= 0:
    count += 1
    ab.pop(idx)
  
print(count)

Submission status: Wrong Answer

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

ab.sort()
cd.sort()

count = 0
for i in range(N):
  x = N - i - 1
  for j in range(len(ab)):
    y = len(ab) - j - 1
    if cd[x][0] > ab[y][0] and cd[x][1] > ab[y][1]:
      ab.pop(y)
      count += 1
      break
print(count)

Submission status: Wrong Answer

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

point=0
for i in range(n):
    for j in range(n):
        if blue[j][0]>red[i][0] and blue[j][1]>red[i][1]:
            point +=1
            blue[j]=[0,0]
            break
print(point)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter

def main():
    N = int(input())
    
    red = [[int(i) for i in input().split()] for i in range(N)]
    blue = [[int(i) for i in input().split()] for i in range(N)]

    # 青よりx,y座標のが小さい赤の中で、最もyが大きいものから削除するため
    # 青はxでソート、赤はyでソートする
    sort_red = sorted(red, key=itemgetter(1))
    sort_blue = sorted(blue, key=itemgetter(0))

    cnt = 0
    for b in sort_blue:
        for r in sort_red:
            if r[0] < b[0] and r[1] < b[1]:
                cnt += 1
                sort_red.remove(r)
                break
    print(cnt)


main()

Submission status: Wrong Answer

Solution code:
from operator import itemgetter

def main():
    N = int(input())
    
    red = [[int(i) for i in input().split()] for i in range(N)]
    blue = [[int(i) for i in input().split()] for i in range(N)]

    sort_red = sorted(red, key=itemgetter(0))
    sort_blue = sorted(blue, key=itemgetter(0))

    cnt = 0
    for i in range(N):
        max_y = -1
        tmp_index = -1
        for j in range(len(sort_red)):
            if sort_blue[i][0] > sort_red[j][0]:
                if max_y < sort_red[j][1]:
                    max_y = sort_red[j][1]
                    tmp_index = j
            else:
                break
        if max_y >= 0:
            sort_red.pop(tmp_index)
            cnt += 1
    print(cnt)


main()

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)]
ans = 0
ap = []


for i in range(n):
    for j in range(n):
        if ab[i][0] < cd[j][0] and ab[i][1] < cd[j][1]:
            if ab[i] not in ap and cd[j] not in ap:
                ap.append(ab[i])
                ap.append(cd[j])
                ans += 1

print(ans)

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()
print(b)
ans = 0
for i in range(n):
    Bx = b[i][0]
    By = b[i][1]
    tmp = []
    for j in range(len(r)):
        if r[j][0] <= Bx and r[j][1] <= By:
            dis = (Bx - r[j][0])**2 + (By - r[j][1])**2
            tmp.append([r[j][1],[r[j][0],r[j][1]]])
    if len(tmp) == 0:
        continue
    else:
        tmp.sort(reverse=True)
        ans += 1
        r.remove(tmp[0][1])
print(ans)