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:

def Plane_2N(n, abli, cdli):

    ans = 0
    count = [0]*n
    sorted_abli = sorted(abli, key=lambda x: (x[0], x[1]))
    sorted_cdli = sorted(cdli, key=lambda x: (x[0], x[1]))

    for i in range(n):
        flag = False
        for w in range(n):
            if sorted_abli[i][0] < sorted_cdli[w][0] and sorted_abli[i][1] < sorted_cdli[w][1] and count[w] == 0:
                ans += 1
                count[w] = 1
                flag = True
            if flag == True:
                break

    return ans

def main():
    n = int(input())
    abli = [list(map(int, input().split())) for i in range(n)]
    cdli = [list(map(int , input().split())) for i in range(n)]
    print(Plane_2N(n , abli , cdli))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:

def Plane_2N(n, abli, cdli):

    ans = 0
    count = [0]*n
    sorted_abli = sorted(abli, key=lambda x: (x[0], x[1]))
    sorted_cdli = sorted(cdli, key=lambda x: (x[0], x[1]))

    for i in range(n):
        flag = False
        for w in range(n):
            if abli[i][0] < cdli[w][0] and abli[i][1] < cdli[w][1] and count[w] == 0:
                ans += 1
                count[w] = 1
                flag = True
            if flag == True:
                break

    return ans

def main():
    n = int(input())
    abli = [list(map(int, input().split())) for i in range(n)]
    cdli = [list(map(int , input().split())) for i in range(n)]
    print(Plane_2N(n , abli , cdli))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:

def Plane_2N(n, abli, cdli):

    ans = 0
    count = [0]*n
    abli.sort(reverse=True)

    for i in range(n):
        flag = False
        for w in range(n):
            if abli[i][0] < cdli[w][0] and abli[i][1] < cdli[w][1] and count[w] == 0:
                ans += 1
                count[w] = 1
                flag = True
            if flag == True:
                break

    return ans

def main():
    n = int(input())
    abli = [list(map(int, input().split())) for i in range(n)]
    cdli = [list(map(int , input().split())) for i in range(n)]
    print(Plane_2N(n , abli , cdli))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def count_pairs(a, b):
    i = k = cnt = 0
    while i < n and k < n:
        if a[i][0] < b[k][0] and a[i][1] < b[k][1]:
            cnt += 1
            i += 1
        k += 1
    return cnt

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

print(max(count_pairs(sorted(red), sorted(blue)), count_pairs(sorted(red, key=lambda x: x[1]), sorted(blue, key=lambda x: x[1]))))

Submission status: Wrong Answer

Solution code:
N=int(input())
A=[]
B=[]
AN=[]
BN=[]
for a in range(N):
    b=input().split()
    A.append(b)
    z=[y for y in b]
    z.reverse()
    AN.append(z)
for c in range(N):
    d=input().split()
    B.append(d)
    x=[w for w in d]
    x.reverse()
    BN.append(x)
AA=sorted(A)
BB=sorted(B)
AAA=sorted(AN,reverse=True)
BBB=sorted(BN)
number=0
for a in AAA:
    a.reverse()
for b in BB:
    for a in AAA:
        if b[0]>a[0] and b[1]>a[1]:
            number+=1
            AAA.remove(a)
            break
print(number)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=[]
B=[]
AN=[]
BN=[]
for a in range(N):
    b=input().split()
    A.append(b)
    z=[y for y in b]
    z.reverse()
    AN.append(z)
for c in range(N):
    d=input().split()
    B.append(d)
    x=[w for w in d]
    x.reverse()
    BN.append(x)
AA=sorted(A)
BB=sorted(B)
AAA=sorted(AN,reverse=True)
BBB=sorted(BN)
number=0
for a in AAA:
    a.reverse()
for b in BB:
    for a in AAA:
        if b[0]>a[0] and b[1]>a[1]:
            number+=1
            AAA.remove(a)
            break


print(number)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=[]
B=[]
AN=[]
BN=[]
for a in range(N):
    b=input().split()
    A.append(b)
    z=[y for y in b]
    z.reverse()
    AN.append(z)
for c in range(N):
    d=input().split()
    B.append(d)
    x=[w for w in d]
    x.reverse()
    BN.append(x)
AA=sorted(A)
BB=sorted(B)
AAA=sorted(AN)
BBB=sorted(BN)
number=0
for b in BB:
    for a in AA:
        if b[0]>a[0] and b[1]>a[1]:
            number+=1
            AA.remove(a)
            break
answer=0
for b in BBB:
    for a in AAA:
        if b[0]>a[0] and b[1]>a[1]:
            answer+=1
            AAA.remove(a)
            break
print(max(answer,number))

Submission status: Wrong Answer

Solution code:
#091_C
n = int(input())
ab = [tuple(map(int, input().split())) for _ in range(n)]
cd = [tuple(map(int, input().split())) for _ in range(n)]

ab.sort(key = lambda x:(-x[0],-x[1]))
cd.sort(key = lambda x:(-x[0],-x[1]))
flg = [True for _ in range(n)] 
ans = 0

for i in range(n):
    a, b = ab[i]
    for j in range(n):
        if flg[j]:
            c, d = cd[j]
            if a < c and b < d:
                ans += 1
                flg[j] = False
                break
                
print(ans)

Submission status: Wrong Answer

Solution code:
casen=4
if casen==0:
    a=[]
    c=[]
    n=int(input())
    for i in range(n):
        ai,bi=map(int,input().split())
        a.append([ai,bi])
    for i in range(n):
        ci,di=map(int,input().split())
        c.append([ci,di])
elif casen==1:
    n=3
    a=[[0,0],[1,1],[5,2]]
    c=[[2,3],[3,4],[4,5]]
elif casen==4:
    n=5
    a=[[0,0],[7,3],[2,2],[4,8],[1,6]]
    c=[[8,5],[6,9],[5,4],[9,1],[3,7]]

a.sort()
c.sort()

import itertools
 
#n = 3
#    n = int(input())
lis = [x for x in range(n)] # 0からn-1までのリスト
 
permutations_lis = itertools.permutations(lis)# 全ての場合のリストを生成
# 以下出力
icmax=0
for one_case in permutations_lis: 
#    print(list(one_case))
    icnt=0
    for i in range(n):
        ii=one_case[i]
        if a[i][0]<c[ii][0] and a[i][1]<c[ii][1]:
            icnt=icnt+1
    if icmax<icnt:
        icmax=icnt

print(icmax)

Submission status: Wrong Answer

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

#n=3
#a=[[0,0],[1,1],[5,2]]
#c=[[2,3],[3,4],[4,5]]

a.sort()
c.sort()

s=[]
t=[]
for ia in range(n):
    for ic in range(n):
        if a[ia][0]<c[ic][0]:
            s.append([a[ia],c[ic]])
            t.append([ia,ic,0])
#for ss in s:
#    print(ss)    
#for tt in t:
#    print(tt,a[tt[0]],c[tt[1]])    
     
icnt=0
ic2=0
for ia in range(len(a)):
    t2=[tt for tt in t if (tt[0]==a[ia][0] and tt[2]==0)]
#    print(t2)
    if len(t2)>=1:
        icnt=icnt+1
        ic2=t2[0][1]
        for tt in t:
            if tt[1]==ic2:
                tt[2]=1
#    print(t)
print(icnt)

Submission status: Wrong Answer

Solution code:
N = int(input())

lr = []
for i in range(N):
  a,b = map(int,input().split())
  lr.append([a,b,a**2+b**2])
lr.sort(key=lambda x:x[1])
lr.sort(key=lambda x:x[0])

lb = []
for i in range(N):
  c,d = map(int,input().split())
  lb.append([c,d,c**2+d**2])
lb.sort(key=lambda x:x[2])

cnt=0
while len(lr) > 0:
  v = lr.pop()
  for j in reversed(range(len(lb))):
    if v[0] < lb[j][0] and v[1] < lb[j][1]:
      del lb[j]
      cnt = cnt+1
      break
    else:
      continue  
print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
ab = []
cd = []
for i in range(N):
    a,b = map(int,input().split())
    ab.append([0,a,b,i])
for i in range(N):
    c,d = map(int,input().split())
    cd.append([0,c,d,i])
cover = []
for i in range(N):
    cnt = 0
    cov = [i]
    for j in range(N):
        if ab[j][1] < cd[i][1] and ab[j][2] < cd[i][2]:
            cnt += 1
            cov.append(j)
    cd[i][0] = cnt
    cover.append(cov)
 
 
cd.sort()
C = []
for i in range(N):
    tmp = cover[cd[i][3]]
    tmp.pop(0)
    C.append(tmp)
cd_dist = []
for i in range(N):
    dist = []
    if cd[i][0] != 0:
        for j in C[i]:
            d = (ab[j][2]-cd[i][2])**2
            dist.append([d,j])
        dist.sort(reverse=True)
        cd_dist.append(dist)
    else:
        cd_dist.append([])
 
flag = [1]*N
ans = 0
for i in range(N):
    for j in C[i]:
        if flag[j]:
            ans += 1
            flag[j] = 0
            break
    ##print(flag)
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())

ab=[]
for _ in range(n):
  ab.append(list(map(int,input().split())))

ab.sort(reverse=True)
  
cd=[]
for _ in range(n):
  cd.append(list(map(int,input().split())))
  
cd.sort(reverse=True)

cnt=0
for item1 in ab:  
  for item2 in cd:
    temp=[]
    if item1[0]<item2[0] and item1[1]<item2[1]:
      temp.append(item2)
    if len(temp)>0:
      temp.sort(key=lambda x: x[1])
      cnt+=1
      #print(temp[0])
      #print("item2",item2)
      cd.remove(temp[0])

print(cnt)

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

from operator import itemgetter
r = sorted(r, key=itemgetter(1),reverse=1)
b = sorted(b)

x=0
y=[100,100]
z=[0,0]

for i in range(n):
    for j in range(n):
        if b[i][0] > r[j][0] and b[i][1] > r[j][1]:
            x+=1
            r[j] = y
            b[i] = z
            break

print(x)

Submission status: Wrong Answer

Solution code:
N = int(input())
ab = []
cd = []
for i in range(N):
    a,b = map(int,input().split())
    ab.append([0,a,b,i])
for i in range(N):
    c,d = map(int,input().split())
    cd.append([0,c,d,i])
cover = []
for i in range(N):
    cnt = 0
    cov = [i]
    for j in range(N):
        if ab[j][1] < cd[i][1] and ab[j][2] < cd[i][2]:
            cnt += 1
            cov.append(j)
    cd[i][0] = cnt
    cover.append(cov)


cd.sort()
C = []
for i in range(N):
    tmp = cover[cd[i][3]]
    tmp.pop(0)
    C.append(tmp)
cd_dist = []
for i in range(N):
    dist = []
    if cd[i][0] != 0:
        for j in C[i]:
            d = (ab[j][1]-cd[i][1])**2+(ab[j][2]-cd[i][2])**2
            dist.append([d,j])
        dist.sort(reverse=True)
        cd_dist.append(dist)
    else:
        cd_dist.append([])

flag = [1]*N
ans = 0
for i in range(N):
    for j in C[i]:
        if flag[j]:
            ans += 1
            flag[j] = 0
            break
    ##print(flag)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
ab = []
cd = []
for i in range(N):
    a,b = map(int,input().split())
    ab.append([0,a,b,i])
for i in range(N):
    c,d = map(int,input().split())
    cd.append([0,c,d,i])
cover = []
for i in range(N):
    cnt = 0
    cov = [i]
    for j in range(N):
        if ab[j][1] < cd[i][1] and ab[j][2] < cd[i][2]:
            cnt += 1
            cov.append(j)
    cd[i][0] = cnt
    cover.append(cov)


cd.sort()
C = []
for i in range(N):
    tmp = cover[cd[i][3]]
    tmp.pop(0)
    C.append(tmp)
cd_dist = []
for i in range(N):
    dist = []
    if cd[i][0] != 0:
        for j in C[i]:
            d = (ab[j][1]-cd[i][1])**2+(ab[j][2]-cd[i][2])**2
            dist.append([d,j])
        dist.sort()
        cd_dist.append(dist)
    else:
        cd_dist.append([])

flag = [1]*N
ans = 0
for i in range(N):
    for j in C[i]:
        if flag[j]:
            ans += 1
            flag[j] = 0
            break
    ##print(flag)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
ab = []
cd = []
for i in range(N):
    a,b = map(int,input().split())
    ab.append([0,a,b,i])
for i in range(N):
    c,d = map(int,input().split())
    cd.append([0,c,d,i])
cover = []
for i in range(N):
    cnt = 0
    cov = [i]
    for j in range(N):
        if ab[j][1] < cd[i][1] and ab[j][2] < cd[i][2]:
            cnt += 1
            cov.append(j)
    cd[i][0] = cnt
    cover.append(cov)


cd.sort()
C = []
for i in range(N):
    tmp = cover[cd[i][3]]
    tmp.pop(0)
    C.append(tmp)
cd_dist = []
for i in range(N):
    dist = []
    if cd[i][0] != 0:
        for j in C[i]:
            d = (ab[j][1]-cd[i][1])**2+(ab[j][2]-cd[i][2])**2
            dist.append([d,j])
        dist.sort()
        cd_dist.append(dist)
    else:
        cd_dist.append([])

flag = [1]*N
ans = 0
for i in range(N):
    for j in range(len(cd_dist[i])):
        if flag[cd_dist[i][j][1]]:
            ans += 1
            flag[cd_dist[i][j][1]] = 0
            break
print(ans)

Submission status: Wrong Answer

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

cover = []
for i in range(N):
    cnt = 0
    cov = []
    for j in range(N):
        if ab[j][1] < cd[i][1] and ab[j][2] < cd[i][2]:
            cnt += 1
            cov.append(j)
    cd[i][0] = cnt
    cover.append(cov)

cover.sort()
cd.sort()
cd_dist = []
for i in range(N):
    dist = []
    if cd[i][0] != 0:
        for j in cover[i]:
            d = (ab[j][1]-cd[i][1])**2+(ab[j][2]-cd[i][2])**2
            dist.append([d,j])
        dist.sort()
        cd_dist.append(dist)
    else:
        cd_dist.append([])

flag = [1]*(N+1)
ans = 0
for i in range(N):
    for j in range(len(cover[i])):
        if flag[cd_dist[i][j][1]]:
            ans += 1
            flag[cd_dist[i][j][1]] = 0
            break

print(ans)

Submission status: Wrong Answer

Solution code:
# 雑にソートして全探索じゃ駄目なのかな
n = int(input())
reds = []
blues = []
for _ in range(n):
    reds.append(tuple(map(int, input().split())))
for _ in range(n):
    blues.append(tuple(map(int, input().split())))

# y座標降順
reds = sorted(reds, key=lambda x: x[1], reverse=True)
blues = sorted(blues, key=lambda x: x[1], reverse=True)

ans = 0
used_red = [False for _ in range(n)]
for b in blues:
    for i, r in enumerate(reds):
        if used_red[i]:
            continue
        if b[0] > r[0] and b[1] > r[1]:
            # print("青{}と赤{}をセットにする".format(b, r))
            ans += 1
            used_red[i] = True
            break
print(ans)

Submission status: Wrong Answer

Solution code:
# 雑にソートして全探索じゃ駄目なのかな
n = int(input())
reds = []
blues = []
for _ in range(n):
    reds.append(tuple(map(int, input().split())))
for _ in range(n):
    blues.append(tuple(map(int, input().split())))

# y座標降順
reds = sorted(reds, key=lambda x: x[1], reverse=True)
blues = sorted(blues, key=lambda x: x[1], reverse=True)

ans = 0
used_red = [False for _ in range(n)]
for b in blues:
    for i, r in enumerate(reds):
        if used_red[i]:
            continue
        if b[0] > r[0] and b[1] > r[1]:
            # print("青{}と赤{}をセットにする".format(b, r))
            ans += 1
            used_red[i] = True
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
x = [inpl() for i in range(n)]
y = [inpl() for i in range(n)]
x.sort(reverse=True)
y.sort(reverse=True)
res = 0
used = set()
for i in range(n):
    a,b = x[i][0], x[i][1]
    for j in range(n):
        c,d = y[j][0], y[j][1]
        if a<c and b<d and not j in used:
            res += 1
            used.add(j)
            break
print(res)

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()
used=[False]*n
cnt=0
for i in range(n):
    a,b=AB[i]
    ymin=10**20
    for j in range(n):
        c,d=CD[j]
        if a>c:
            continue
        if used[j]:
            continue
        if b<d:
            ymin=min(ymin,d)
    for j in range(n):
        if CD[j][1]==ymin:
            used[j]=True
print(sum(used))

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()
used=[False]*n
cnt=0
for i in range(n):
    a,b=AB[i]
    ymax=-1
    for j in range(n):
        c,d=CD[j]
        if a>c:
            continue
        if used[j]:
            continue
        if d<b:
            ymax=max(ymax,d)
    for j in range(n):
        if CD[j][1]==ymax:
            used[j]=True
            cnt+=1
print(cnt)

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()
used=[False]*n
cnt=0
for i in range(n):
    a,b=AB[i]
    ymax=-1
    for j in range(n):
        c,d=CD[j]
        if a>c:
            continue
        if used[j]:
            continue
        ymax=max(ymax,d)
    for j in range(n):
        if CD[j][1]==ymax:
            used[j]=True
            cnt+=1
print(cnt)

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()
used=[False]*n
cnt=0
for i in range(n):
    a,b=AB[i]
    ymax=0
    for j in range(n):
        c,d=CD[j]
        if a>c:
            continue
        if used[j]:
            continue
        ymax=max(ymax,d)
    for j in range(n):
        if CD[j][1]==ymax:
            used[j]=True
            cnt+=1
print(cnt)

Submission status: Wrong Answer

Solution code:


N = int(input())
red = []
blue = []
for i in range(N):
    a,b = map(int,input().split())
    red.append([a,b])
for i in range(N):
    c,d = map(int,input().split())
    blue.append([c,d])


#red.sort(key=lambda x: x[0])
used_red = [0]*N
used_blue = [0]*N
"""
for i in range(N):
    idx = -1
    for j in range(N):
        if used_blue[j] != 0:
            continue
        if blue[j][0]-red[i][0]>0 and blue[j][1]-red[i][1]>0:
            if idx == -1:
                idx = j
            else:
                if blue[j][0]<blue[idx][0] and blue[j][1]<blue[idx][1]:
                    idx = j
    if idx != -1:
        used_blue[idx] += 1
print(sum(used_blue))
"""

for i in range(N):
    if used_red[i] != 0:
        i += 1
        continue
    for j in range(N):
        if used_blue[j] != 0:
            continue
        idx = -1
        if blue[j][0]-red[i][0]>0 and blue[j][1]-red[i][1]>0:
            for k in range(N):
                if used_red[k] != 0:
                    continue
                if idx < 0:
                    if blue[j][0]-red[k][0]>0 and blue[j][1]-red[k][1]>0 and red[k][0]-red[i][0]>0 and red[k][1]-red[i][1]>0:
                        idx = k
                else:
                    if blue[j][0]-red[idx][0]>0 and blue[j][1]-red[idx][1]>0 and red[k][0]-red[idx][0]>0 and red[k][1]-red[idx][1]>0:
                        idx = k
        if idx < 0:
            continue
        else:
            used_red[idx] += 1
            used_blue[j] += 1
            
for j in range(N):
    if used_red[0] == 0 and used_blue[j] == 0 and blue[j][0]-red[0][0]>0 and blue[j][1]-red[0][1]>0:
        used_red[0] += 1

print(sum(used_red))

Submission status: Wrong Answer

Solution code:
INF = float("inf") #const
MOD = 10**9+7 #const
MAX = 510000 #const

import fractions
import itertools

def main():
    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[1])

    ans = 0
    for red in ab:
        for blue in cd:
            if red[0] < blue[0] and red[1] < blue[1]:
                ans += 1
                blue[1] = -1
                break

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
INF = float("inf") #const
def main():
    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[1])

    i = 0
    ans = 0
    used = []
    for i in range(n):
        memo = []
        x = ab[i][0]
        for j in range(n):
            if x < cd[j][0]:
                if not j in used:
                    memo.append(j)
        y = ab[i][1]
        for k in memo:
            if y < cd[k][1]:
                used.append(k)
                ans += 1
                break
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
# coding: utf-8


def solve(*args: str) -> str:
    n = int(args[0])
    R = [tuple(map(int, ab)) for ab in map(str.split, args[1:n+1])]
    B = [tuple(map(int, ab)) for ab in map(str.split, args[n+1:2*n+1])]

    R.sort(key=lambda x: (-x[0], -x[1]))
    B.sort(key=lambda x: (-x[0], -x[1]))

    count = 0
    used = [False]*n
    for i in range(n):
        rx, ry = R[i]
        for j in range(n):
            if used[j]:
                continue
            bx, by = B[j]
            if rx < bx and ry < by:
                count += 1
                used[j] = True
                break

    return str(count)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

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

used = defaultdict(int)

ans = 0
for a, b in R:
    temp_dis = float('inf')
    temp_point = None
    for c, d in B:
        if a >= c or b >= d or used[(c, d)] == 1:
            continue
        dis = ((a - c)**2 + (b - d)**2)**0.5
        if dis < temp_dis:
            temp_dis = dis
            temp_point = (c, d)
    if temp_point is not None:
        used[temp_point] = 1
        ans += 1
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(A, key=lambda x: -x[1])  # sort by y-axis [max,..., min]
B = sorted(B, key=lambda x: x[0])   # sort by x-axis [min,..., max]

for i in range(N):
    for j in range(len(A)):
        if A[j][0] < B[i][0] and A[j][1] < B[i][0]:
            A.pop(j)
            break

print(N - len(A))

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(A, key=lambda x: -x[1])  # sort by y-axis [max,..., min]
B = sorted(B, key=lambda x: x[0])   # sort by x-axis [min,..., max]

for i in range(N):
    for j in range(len(A)):
        if A[j][0] < B[i][0]:
            A.pop(j)
            break

print(N - len(A))

Submission status: Wrong Answer

Solution code:
N = int(input())
R = [list(map(int, input().split())) for n in range(N)]
B = [list(map(int, input().split())) for n in range(N)]

RY = sorted(R, key=lambda x: x[1])
BX = sorted(B, key=lambda x: x[0])

ans = 0

for b in BX:
  for index, r in enumerate(RY):
    if b[0] > r[0] and b[1] > r[1]:
      ans += 1
      RY.pop(index)
      break

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
R = [list(map(int, input().split())) for n in range(N)]
B = [list(map(int, input().split())) for n in range(N)]

RX = sorted(R, key=lambda x: x[0])
RY = sorted(R, key=lambda x: x[1])

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

count1 = 0
indexs = []

for r in RX:
  for index, b in enumerate(BX):    
    if r[0] < b[0] and r[1] < b[1] and not index in indexs:
      count1 += 1
      indexs.append(index)
      break

count2 = 0
indexs = []

for r in RY:
  for index, b in enumerate(BY):      
    if r[0] < b[0] and r[1] < b[1] and not index in indexs:
      count2 += 1
      indexs.append(index)
      break
      
count3 = 0
indexs = []

for r in RX:
  for index, b in enumerate(BY):      
    if r[0] < b[0] and r[1] < b[1] and not index in indexs:
      count3 += 1
      indexs.append(index)
      break
      
count4 = 0
indexs = []

for r in RY:
  for index, b in enumerate(BX):      
    if r[0] < b[0] and r[1] < b[1] and not index in indexs:
      count4 += 1
      indexs.append(index)
      break

print(max(count1, count2, count3, count4))

Submission status: Wrong Answer

Solution code:
N = int(input())
R = [list(map(int, input().split())) for n in range(N)]
B = [list(map(int, input().split())) for n in range(N)]

RX = sorted(R, key=lambda x: x[0])
RY = sorted(R, key=lambda x: x[1])

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

count1 = 0
indexs = []

for r in RX:
  for index, b in enumerate(BX):    
    if r[0] < b[0] and r[1] < b[1] and not index in indexs:
      count1 += 1
      indexs.append(index)
      break

count2 = 0
indexs = []

print(max(count1, count2))

Submission status: Wrong Answer

Solution code:
N = int(input())
R = [list(map(int, input().split())) for n in range(N)]
B = [list(map(int, input().split())) for n in range(N)]

RX = sorted(R, key=lambda x: x[0])
RY = sorted(R, key=lambda x: x[1])

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

count1 = 0
indexs = []

for r in RX:
  for index, b in enumerate(BX):    
    if r[0] < b[0] and r[1] < b[1] and not index in indexs:
      count1 += 1
      indexs.append(index)
      break

count2 = 0
indexs = []

for r in RY:
  for index, b in enumerate(BY):      
    if r[0] < b[0] and r[1] < b[1] and not index in indexs:
      count2 += 1
      indexs.append(index)
      break

print(max(count1, count2))

Submission status: Wrong Answer

Solution code:
n=int(input())
p=[]
q=[]
for _ in range(n):
    a,b=map(int,input().split())
    p.append((a,b))
for _ in range(n):
    a,b=map(int,input().split())
    q.append((a,b))

p.sort(key= lambda x:[x[0]+x[1],x[0],x[1]])
q.sort(key= lambda x:[x[0]+x[1],x[0],x[1]])
ans=0
i=0
while len(p)>0:
    #print(p,q)
    x = p.pop()
    for y in q[::-1]:
        if x[0]<y[0] and x[1]<y[1]:
            q.remove(y)
            #print(x,y)
            ans+=1
            break
    else:
        pass
    i+=1
    if i >=200*n:
        break
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
p=[]
q=[]
for _ in range(n):
    a,b=map(int,input().split())
    p.append((a,b))
for _ in range(n):
    a,b=map(int,input().split())
    q.append((a,b))

p.sort(key= lambda x:[x[0]+x[1],x[0],x[1]])
q.sort(key= lambda x:[x[0]+x[1],x[0],x[1]])
ans=0
i=0
while len(p)>0:
    #print(p,q)
    x = p.pop()
    for y in q[::-1]:
        if x[0]<y[0] and x[1]<y[1]:
            q.remove(y)
            #print(x,y)
            ans+=1
            break
    else:
        pass
    i+=1
    if i >=2*n:
        break
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
p=[]
q=[]
for _ in range(n):
    a,b=map(int,input().split())
    p.append((a,b))
for _ in range(n):
    a,b=map(int,input().split())
    q.append((a,b))

p.sort(key= lambda x:[x[0]+x[1],x[0],x[1]])
q.sort(key= lambda x:[x[0]+x[1],x[0],x[1]])
ans=0
i=0
while len(q)>0:
    #print(p,q)
    x = q.pop()
    for y in p[::-1]:
        if x[0]>y[0] and x[1]>y[1]:
            p.remove(y)
            #print(x,y)
            ans+=1
            break
    else:
        pass
    i+=1
    if i >=2*n:
        break
print(ans)

Submission status: Wrong Answer

Solution code:
points = int(input())
p_red = sorted([list(map(int, input().split(' '))) for _ in range(points)])
p_blue = sorted([list(map(int, input().split(' '))) for _ in range(points)])
p_bule_flg = [False for _ in range(len(p_blue))]
pair_count = 0
for p_r in p_red:
    for f, p_b in enumerate(p_blue):
        if p_bule_flg[f] == True:
            continue
        if p_r[0] < p_b[0] and p_r[1] < p_b[1]:
            pair_count += 1
            p_bule_flg[f] = True
            break
print(pair_count)

Submission status: Wrong Answer

Solution code:
points = int(input())
p_red = sorted([list(map(int, input().split(' '))) for _ in range(points)])
p_blue = sorted([list(map(int, input().split(' '))) for _ in range(points)])
p_bule_flg = [False for _ in range(len(p_blue))]
pair_count = 0
for p_r in p_red:
    for f, p_b in enumerate(p_blue):
        if p_bule_flg[f] == True:
            continue
        if p_r[0] < p_b[0] and p_r[1] < p_b[1]:
            pair_count += 1
            p_bule_flg[f] = True
            print(pair_count, p_r, p_b)
            break
print(pair_count)

Submission status: Wrong Answer

Solution code:
def solve():
    N = int(input())
    R = [[int(x) for x in input().split()] for i in range(N)]
    B = [[int(x) for x in input().split()] for i in range(N)]

    selected = set()
    lst = []
    dict = {}
    res = 0
    for i in range(N):
        dict[i] = []
        for j in range(N):
            if R[i][0] < B[j][0] and R[i][1] < B[j][1]:
                dict[i].append(j)
    for i in range(N):
        lst.append([len(dict[i]), i])
    lst.sort()
    for i in range(len(lst)):
        if lst[i][0] == 0:
            continue
        for j in range(len(dict[lst[i][1]])):
            if dict[lst[i][1]][j] in selected:
                continue
            selected.add(dict[lst[i][1]][j])
            res += 1
            break
    return res

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

Submission status: Wrong Answer

Solution code:
def solve():
    N = int(input())
    R = [[int(x) for x in input().split()] for i in range(N)]
    B = [[int(x) for x in input().split()] for i in range(N)]

    pair = set()
    R.sort()
    B.sort()
    for r in R:
        m = 1000
        m_i = 1000
        for i in range(N):
            b = B[i]
            if i in pair:
                continue
            if (r[0] < b[0] and r[1] < b[1]) and min(b[0] - r[0], b[1] - r[1]) < m:
                m = min(b[0] - r[0], b[1] - r[1])
                m_i = i
        if m_i < N:
            pair.add(m_i)
    return len(pair)

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