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:
import numpy as np


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

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

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

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

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

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

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

    print(cnt)


main()

Submission status: Wrong Answer

Solution code:
import numpy as np


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

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

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

    blue[:, 2] = np.max(blue[:, :])
    blue = blue[np.argsort(blue[:, 2])[::-1]]

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

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

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

    print(cnt)


main()

Submission status: Wrong Answer

Solution code:
import numpy as np


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

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

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

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

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

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

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

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

    print(cnt)


main()

Submission status: Wrong Answer

Solution code:
import numpy as np


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

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

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

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

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

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

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

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

    print(cnt)


main()

Submission status: Wrong Answer

Solution code:
import numpy as np


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

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

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

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

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

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

    print(cnt)


main()

Submission status: Wrong Answer

Solution code:
import numpy as np


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

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

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

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

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

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

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

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

    print(cnt)


main()

Submission status: Wrong Answer

Solution code:
from operator import itemgetter

N = int(input())
R = [[int(a) for a in input().split()] for _ in range(N)]
B = [[int(c) for c in input().split()] for _ in range(N)]

for i in range(N):
    R[i].append(max(R[i][0], R[i][1]))
    B[i].append(min(B[i][0], B[i][1]))
    
R.sort(reverse=True, key=itemgetter(2))
B.sort(key=itemgetter(2))

used = [0]*N
for i in range(N):
    d = 10**6
    d2 = 10**6
    idx = -1
    for j in range(N):
        if R[i][0] < B[j][0] and R[i][1] < B[j][1] and used[j] == 0:
            d_temp = min(B[j][0]-R[i][0], B[j][1]-R[i][1])
            d2_temp = max(B[j][0]-R[i][0], B[j][1]-R[i][1])
            if d > d_temp:
                idx = j
                d = d_temp
                d2 = d2_temp
            elif d == d_temp and d2 > d2_temp:
                idx = j
                d2 = d2_temp
    if idx >= 0:
        used[idx] = 1
    
print(sum(used))

Submission status: Wrong Answer

Solution code:
N=int(input())
A = [0] * N
B = [0] * N
for n in range(N):
  A[n] = [int(x) for x in input().split()]
for n in range(N):
  B[n] = [int(x) for x in input().split()]

B.sort(key=lambda x:x[1])
B.sort()
print(A)
print(B)
ans = 0
for b in B:
  A.sort(key=lambda x:x[1])
  A.sort()
  q = [a for a in A if a[0] < b[0] and a[1] < b[1]]
  q_ = [a for a in A if a[0] >= b[0] or a[1] >= b[1]]
  maxa = -1
  if q:
    for i, qq in enumerate(q):
      if qq[1] > maxa:
        maxi = i
        maxa = qq[1]
    q.pop(maxi)
    ans += 1
  A = q[:] + q_[:]

print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[]
for i in range(n):
    a.append(list(map(int,input().split())))
b=[]
for i in range(n):
    b.append(list(map(int,input().split())))
a.sort()
b.sort()
ans=0
for i in range(n):
    tmp=[]
    f=0
    for j in a:
        if f==0 and j[0]<b[i][0] and j[1]<b[i][1]:
            ans+=1
            f=1
        else:
            tmp.append(j)
    a=tmp
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[]
for i in range(n):
    a.append(list(map(int,input().split())))
b=[]
for i in range(n):
    b.append(list(map(int,input().split())))
a.sort()
b.sort()
ans=0
for i in range(n):
    tmp=[]
    for j in a:
        if j[0]<b[i][0] and j[1]<b[i][1]:
            ans+=1
        else:
            tmp.append(j)
    a=tmp
print(ans)

Submission status: Wrong Answer

Solution code:
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n = int(readline())
    ab = [list(map(int, readline().split())) for _ in range(n)]
    ab.sort(reverse=True)
    cd = [list(map(int, readline().split())) for _ in range(n)]
    cd.sort(reverse=True)
    cnt = 0
    for i in range(n):
        for j in range(n):
            if ab[i][0] <= cd[j][0] and ab[i][1] <= cd[j][1]:
                cnt += 1
                cd[j][0] = cd[j][1] = 0
                break
    print(cnt)


if __name__ == '__main__':
    solve()

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)]
res = 0
bf = [[] for _ in range(n)]
for i in range(n):
    for j in range(n):
        if red[j][0]<blue[i][0] and red[j][1]<blue[i][1]:
            bf[i].append(j)
bf.sort(key=lambda x : len(x))
for i in range(n):
    if bf[i]:
        res +=1
        pair = bf[i][0]
        for j in range(n):
            if pair in bf[j]:
                bf[j].remove(pair) 
print(res)

Submission status: Wrong Answer

Solution code:
n = int(input())
AB = []
for i in range(n):
    a,b=map(int,input().split())
    AB.append([a,b])
CD = []
for i in range(n):
    c,d=map(int,input().split())
    CD.append([c,d])
coutAB = []
coutCD = []
count = 0
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 coutAB and CD[j] not in coutCD:
                count+=1
                coutAB.append(AB[i])
                coutCD.append(CD[j])
print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
AB = []
for i in range(n):
    a,b=map(int,input().split())
    AB.append([a,b])
CD = []
for i in range(n):
    c,d=map(int,input().split())
    CD.append([c,d])
coutAB = []
coutCD = []
count = 0
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 coutAB and CD[j] not in coutCD:
                count+=1
                coutAB.append(AB[i])
                coutCD.append(CD[j])
print(coutAB)
print(coutCD)
print(count)

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)]
cnt=0
for bb in b:
    t_r=[-1,-1]
    for rr in r:
        if rr[0]<bb[0] and rr[1]<bb[1] and (bb[0]-rr[0])**2+(bb[1]-rr[1])**2 < (bb[0]-t_r[0])**2+(bb[1]-t_r[1])**2:
            t_r=rr
    if t_r!=[-1,-1]:
        cnt+=1
        r.remove(t_r)
print(cnt)

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)]
cnt=0
for bb in b:
    t_r=[-1,-1]
    for rr in r:
        if rr[0]<bb[0] and rr[1]<bb[1] and rr[0]+rr[1]>t_r[0]+t_r[1]:
            t_r=rr
    if t_r!=[-1,-1]:
        cnt+=1
        r.remove(t_r)
print(cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
ab, cd = [], []
for _ in range(n):
    ab.append([int(x) for x in input().split()])
for _ in range(n):
    cd.append([int(x) for x in input().split()])
ab.sort(key=lambda x: x[0])
cd.sort(key=lambda x: x[1], reverse=True)
pair_cnt = 0
for cdleftmost in cd:
    for abi in ab:
        if(abi[0] < cdleftmost[0] and abi[1] < cdleftmost[1]):
            ab.remove(abi)
            pair_cnt += 1
            break
print(pair_cnt)

Submission status: Wrong Answer

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

for i in range(0,n):
    x,y=map(int,input().split())
    blue.append([x,y])

ans=0
tmp=400
red.sort()
blue.sort()

red2=red
blue2=blue
red2.sort(key=lambda x: x[1])
blue2.sort(key=lambda x: x[1])

for i in range(0,n):
    for j in range(0,n):
        if red[i][0]<blue[j][0] and red[i][1]<blue[j][1]:
            ans+=1
            blue[j][0]=-1
            blue[j][1]=-1
            red[i][0]=tmp
            red[i][1]=tmp

cnt=0
for i in range(0,n):
    for j in range(0,n):
        if red2[i][0]<blue2[j][0] and red2[i][1]<blue2[j][1]:
            cnt+=1
            blue2[j][0]=-1
            blue2[j][1]=-1
            red2[i][0]=tmp
            red2[i][1]=tmp

print(max(ans,cnt))

Submission status: Wrong Answer

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

for i in range(0,n):
    x,y=map(int,input().split())
    blue.append([x,y])

ans=0
tmp=400
red.sort()
blue.sort()

for i in range(0,n):
    for j in range(0,n):
        if red[i][0]<blue[j][0] and red[i][1]<blue[j][1]:
            ans+=1
            blue[j][0]=-1
            blue[j][1]=-1
            red[i][0]=tmp
            red[i][1]=tmp

print(ans)

Submission status: Wrong Answer

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

sab.sort(reverse=True)
scd.sort()
ans = 0

for i in range(N):
    for j in range(len(sab)):
        if sab[j][1] < scd[i][1] and sab[j][2] < scd[i][2]:
            ans += 1
            del sab[j]
            break
print(ans)

Submission status: Wrong Answer

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

sab.sort(reverse=True)
scd.sort(reverse=True)
ans = 0

for i in range(N):
    for j in range(len(sab)):
        if sab[j][1] < scd[i][1] and sab[j][2] < scd[i][2]:
            ans += 1
            del sab[j]
            break
print(ans)

Submission status: Wrong Answer

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

sab.sort(reverse=True)
scd.sort(reverse=True)
ans = 0
for i in range(N):
    for j in range(len(ab)):
        if sab[j][1] < scd[i][1] and sab[j][2] < scd[i][2]:
            ans += 1
            del ab[j]
            break
print(ans)

Submission status: Wrong Answer

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

ab.sort(reverse=True)
cd.sort(reverse=True)
ans = 0
for i in range(N):
    for j in range(len(ab)):
        if ab[j][0] < cd[i][0] and ab[j][1] < cd[i][1]:
            ans += 1
            del ab[j]
            break
print(ans)

Submission status: Wrong Answer

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

for i in range(n):
    b.append(list(map(int,input().split())))

r.sort()
b.sort()

ans=0
for i in range(n):
    j=(n-1)-i
    bc,bd=list(zip(*b))
#    print(bc)
    bj_morethan_aj = bisect.bisect_left(bc, r[j][0])
    while(bj_morethan_aj < len(b)):
        if(r[j][1] < b[bj_morethan_aj][1]):
            ans+=1
            del b[bj_morethan_aj]
            break
        else:
            bj_morethan_aj+=1
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[]
b=[]
for i in range(n):
    a.append(list(map(int,input().split())))
for i in range(n):
    b.append(list(map(int,input().split())))
c=[[] for i in range(n)]
for bi in range(n):
    for ai in range(n):
        if a[ai][0]<b[bi][0] and a[ai][1]<b[bi][1]:
            c[bi].append(a[ai])
z=[]
cin=0
for i in range(n):
    if len(c[i])>0:
        cin+=1
        for j in c[i]:
            if not j in z:
                z.append(j)
print(min(cin,len(z)))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
import bisect

def main():
    N= int(input())
    red = [list(map(int,input().split())) for _ in range(N)]
    blue = [list(map(int,input().split())) for _ in range(N)]
    red.sort(key= lambda x:(x[0],-x[1]))
    red_x = [r[0] for r in red]
    blue.sort(key= lambda x:x[0])
    answer = 0
    for i  in range(N):
        b = blue[i][0]
        max_x_index = bisect.bisect_left(red_x,b)
        search_target_red = red[:max_x_index]
        max_y = 0 
        max_index = -1
        for i,r in enumerate(search_target_red[::-1]):
            if r[1]>max_y:
                max_y = r[1]
                max_index=i
        
        if max_index!=-1:
            answer+=1
            red.pop(max_index)
            red_x.pop(max_index)
    
    print(answer)










if __name__ == '__main__':
    main()

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_count = []

for i in range(n):
  count = 0
  index_list = []
  for j in range(n):
    if blue[j][0]>red[i][0] and blue[j][1]>red[i][1]:
      count += 1
      index_list.append(j)
  red_count.append(index_list)
red_count.sort(key=lambda x: len(x))

count = 0
for i in range(len(red_count)):
  if red_count[i]:
    remove_index = red_count[i][0]
    for j in range(len(red_count)):
      if remove_index in red_count[j]:
        red_count[j].remove(remove_index)
    count += 1
  else:
    continue
        
else:
  print(count)

Submission status: Wrong Answer

Solution code:
N=int(input())
AB=[list(map(int,input().split())) for _ in range(N)]
AB_=sorted(AB,key=lambda x:-x[0])
CD=[list(map(int,input().split())) for _ in range(N)]
CD_=sorted(CD,key=lambda x:-x[0])
ans=0
for i in range(N):
    target=[]
    for j in range(len(CD_)):
        if CD_[j][0]>AB_[i][0]:
            target.append(CD_[j])
    target=sorted(target,key=lambda x:x[1])
    if len(target)==0:
        continue
    else:
        ans+=1
        CD_.remove(target[0])
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
red = []
blue = []
for i in range(n):
    red.append(list(map(int, input().split())))
for i in range(n):
    blue.append(list(map(int, input().split())))
red.sort()
red.reverse()
blue.sort()
blue.reverse()
count = 0

s = len(blue)
for i in range(n):
    for j in range(s):
        if red[i][0] < blue[j][0] and red[i][1] < blue[j][1]:
            count += 1
            del blue[j]
            s -= 1
            break
print(count)

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    red = [[int(i) for i in input().split()] + [True] for j in range(N)]
    blue = [[int(i) for i in input().split()] for j in range(N)]
    red.sort(reverse=True)
    blue.sort()
    ans1 = 0
    for b in blue:
        for a in red:
            if a[2] and a[0] < b[0] and a[1] < b[1]:
                ans1 += 1
                a[2] = False
                break

    red.sort(key=lambda p: p[1],reverse=True)
    red = [[r0,r1,True] for r0,r1,r2 in red]
    blue.sort(key=lambda p: p[1])
    ans2 = 0
    for b in blue:
        for a in red:
            if a[2] and a[0] < b[0] and a[1] < b[1]:
                ans2 += 1
                a[2] = False
                break
    
    print(max(ans1,ans2))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
AB = []
CD = []
for _ in range(N):
    ab = list(map(int, input().split()))
    ab.append(True)
    AB.append(ab)
for _ in range(N):
    cd = list(map(int, input().split()))
    cd.append(True)
    CD.append(cd)
AB.sort(key=lambda x: x[0])
CD.sort(key=lambda x: x[1])
ans = 0

for i in range(N):
    for j in range(N):
        if AB[i][2] and CD[j][2]:
            if AB[i][0] < CD[j][0]:
                if AB[i][1] < CD[j][1]:
                    ans += 1
                    AB[i][2] = False
                    CD[j][2] = False
                    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)]
red.sort(key=lambda x:x[1])
blue.sort(key=lambda x:x[1])
ans = 0
for i in range(n):
    j = i
    if red[i][0] < blue[j][0] and red[i][1] < blue[j][1]:
            ans += 1
    else:
        if j < n:
            j += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
red = [list(map(int,input().split())) for _ in range(n)]
red.sort(key=lambda x:(x[1]))
blue = sorted(list(map(int,input().split())) for _ in range(n))
blue.sort(key=lambda x:(x[0],x[1]))
seen = [False]*n
for i in range(n):
    check = -1
    for j in range(n):
        if seen[j]:continue
        if blue[i][0] > red[j][0]:
            check = j
    if check != -1:seen[check] = True
print(seen.count(True))

Submission status: Wrong Answer

Solution code:
n = int(input())
red = [list(map(int,input().split())) for _ in range(n)]
blue = sorted(list(map(int,input().split())) for _ in range(n))
seen = [False]*n
for i in range(n):
    check = -1
    a = -1
    for j in range(n):
        if seen[j]:continue
        if blue[i][0] > red[j][0]:
            if a < red[j][1]:
                a = red[j][1]
                check = j
    if check != -1:seen[check] = True
print(seen.count(True))

Submission status: Wrong Answer

Solution code:
n = int(input())
red = [list(map(int,input().split())) for _ in range(n)]
red.sort(key=lambda x:(x[1]))
blue = sorted(list(map(int,input().split())) for _ in range(n))
seen = [False]*n
for i in range(n):
    check = -1
    for j in range(n):
        if seen[j]:continue
        if blue[i][0] > red[j][0]:
            check = j
    if check != -1:seen[check] = True
print(seen.count(True))

Submission status: Wrong Answer

Solution code:
N = int(input())
R_dot, B_dot = [],[]
for _ in range(N):
    R_dot.append(list(map(int,input().split()))+[0])
    
# ペアとして使用済かそうでないかを示す要素を追加する
for _ in range(N):
    B_dot.append(list(map(int,input().split()))+[0])

R_dot = sorted(R_dot, key = lambda x: x[1])
R_dot = sorted(R_dot, key = lambda x: x[0])
B_dot = sorted(B_dot, key = lambda x: x[1])
B_dot = sorted(B_dot, key = lambda x: x[0])
    
# x座標とy座標のどちらも小さい赤い点から順に、最も近い青い点を選んで貪欲にペアを作る
ans = 0
for i in range(N):
    tmp_B_dot_dist = []
    for j in range(N):
        if R_dot[i][0] < B_dot[j][0] and R_dot[i][1] < B_dot[j][1] and B_dot[j][2] == 0:
            tmp_B_dot_dist.append(min(abs(R_dot[i][0]-B_dot[j][0]), abs(R_dot[i][1]-B_dot[j][1])))
        else:
            tmp_B_dot_dist.append(-1)
    if sum(tmp_B_dot_dist) != -N:
        if min(tmp_B_dot_dist) == -1:
            B_pair_idx = tmp_B_dot_dist.index(sorted(set(tmp_B_dot_dist))[1])
        else:
            B_pair_idx = tmp_B_dot_dist.index(min(tmp_B_dot_dist))
        ans += 1
        B_dot[B_pair_idx][2] = 1
            
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]+x[1],reverse = True)
cd.sort(key = lambda x: x[0]+x[1])
cd_bool = [True]*n
cnt = 0
for i in range(n):
  for j in range(n):
    if ab[i][0] < cd[j][0] and ab[i][1] < cd[j][1] and cd_bool[j]:
      cnt += 1
      cd_bool[j]= False
      break
print(cnt)

Submission status: Wrong Answer

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


def rindex(wanted_value, list_name):
    indexes = [i for i, x in enumerate(list_name) if x == wanted_value]
    return indexes[-1]


for c, d in blue:
    p = []
    dist = []
    for a, b in red:
        if a < c and b < d:
            p.append([a, b])
            dist.append(d)
        elif a >= c:
            break
    if p:
        red.remove(p[rindex(max(dist), dist)])

print(N - len(red))

Submission status: Wrong Answer

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


def rindex(a, l):
    indexes = [i for i, x in enumerate(l) if x == a]
    return indexes[-1]


for c, d in blue:
    p = []
    dist = []
    for a, b in red:
        if a < c and b < d:
            p.append([a, b])
            dist.append((a - c) ** 2 + (b - d) ** 2)
        elif a >= c:
            break
    if p:
        red.remove(p[rindex(min(dist), dist)])

print(N - len(red))

Submission status: Wrong Answer

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

for c, d in blue:
    p = []
    dist = []
    for a, b in red:
        if a < c and b < d:
            p.append([a, b])
            dist.append((a - c) ** 2 + (b - d) ** 2)
        elif a >= c:
            break
    if p:
        red.remove(p[dist.index(min(dist))])

print(N - len(red))

Submission status: Wrong Answer

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

for c, d in blue:
    p = []
    dist = []
    for a, b in red:
        if a < c and b < d:
            p.append([a, b])
            dist.append((a - c) ** 2 + (b - d) ** 2)
        elif a >= c:
            break
    if p:
        red.remove(p[dist.index(min(dist))])
        ans += 1

print(ans)

Submission status: Wrong Answer

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

for a, b in red:
    for c, d in blue:
        if a < c and b < d:
            blue.remove([c, d])
            ans += 1
            break

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
# 赤い点はy軸が大きい方順にソート
reds = sorted([tuple(map(int, input().split())) for _ in range(N)], key=lambda x: -x[1])
# 青い点はx軸が小さい方順にソート
blues = sorted([tuple(map(int, input().split())) for _ in range(N)], key=lambda x: x[0])

ans = 0
for bx, by in blues:
    for rx, ry in reds:
        if rx < bx and ry < by:
            ans += 1
            print((rx, ry), (bx, by))
            reds.remove((rx, ry))
            break
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)]

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

ans = 0
for r in red:
    for b in blue:
        if r[0] < b[0] and r[1] < b[1]:
            ans += 1
            blue.remove(b)
            break

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

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

ans = 0
for r in red:
    for b in blue:
        if r[0] < b[0] and r[1] < b[1]:
            ans += 1
            blue.remove(b)
            break

print(ans)

Submission status: Wrong Answer

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

s = []
for i in range(n):
    tmp = []
    for j in range(n):
        if p[j][0] < q[i][0] and p[j][1] < q[i][1]:
            tmp.append(j)
    s.append(tmp)
    
s = sorted(s, key=lambda x:len(x))
selected = set([])
for i in range(n):
    tmp = set(s[i])
    tmp = tmp - selected
    if len(tmp) == 0:
        continue
    selected.add(tmp.pop())
print(len(selected))

Submission status: Wrong Answer

Solution code:
import sys


n = int(input())
red = [[int(_) for _ in input().split()] for _ in range(n)]
blue = [[int(_) for _ in input().split()] for _ in range(n)]
l = [[0 for _ in range(n+1)] for _ in range(n)]
ans = 0
for i in range(n):
    for j in range(n):
        if red[i][0] < blue[j][0] and red[i][1] < blue[j][1]:
            l[i][0] += 1
            l[i][j+1] = 1
while True:
    min = float('inf')
    min_idx = -1
    for i in range(n):
        if l[i][0] <= min and l[i][0] != 0:
            min = l[i][0]
            min_idx = i
    if min_idx < 0:
        print(ans)
        sys.exit()
    for i in range(1, n+1):
        if l[min_idx][i] == 1:
            delete_idx = i
            ans += 1
            l[min_idx][0] = 0
            for j in range(n):
                if l[j][delete_idx] == 1 and l[j][0] != 0:
                    l[j][0] -= 1
                    l[j][delete_idx] = 0
            break

Submission status: Wrong Answer

Solution code:
n = int(input())
ab = []
cd = []
for i in range(n):
    ai, bi = map(int, input().split())
    ab.append([ai, bi])
for i in range(n):
    ci, di = map(int, input().split())
    cd.append([ci, di])

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

count = 0
while True:
    if len(cd) == 0:
        break

    flag = 0
    for i in range(len(cd)):
        if ab[i][0] < cd[0][0] and ab[i][1] < cd[0][1]:
            flag = 1
            break

    if flag:
        ab.pop(i)
        count += 1
    cd.pop(0)

print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
ab = []
cd = []
for i in range(n):
    ai, bi = map(int, input().split())
    ab.append([ai, bi])
for i in range(n):
    ci, di = map(int, input().split())
    cd.append([ci, di])

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

count = 0
while True:
    if len(cd) == 0:
        break

    flag = 0
    for i in range(len(cd)):
        if ab[i][0] < cd[0][0]:
            flag = 1
            break
    if flag:
        ab.pop(i)
        count += 1
    cd.pop(0)

print(count)

Submission status: Wrong Answer

Solution code:
Red  = []
Blue = []

def match_and_remove(x,y):
    maxy  = -1
    index = -1
    for i in range(len(Red)):
        rx = Red[i][0]
        ry = Red[i][1]
        if rx < x and ry < y:
            if maxy < ry:
                maxy = ry
                index = i
    if index != -1:
        Red.pop(index)
        return True
    else:
        return False

N = int(input())
for _ in range(N):
    a,b = map(int,input().split())
    Red.append([a,b])
for _ in range(N):
    c,d = map(int,input().split())
    Blue.append([c,d])
ans = 0
for blue in Blue:
    x = blue[0]
    y = blue[1]
    ret = match_and_remove(x,y) 
    if ret:
        ans += 1
print(ans)