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:
#coding: utf-8
import math
import heapq
import bisect
import numpy as np
from collections import Counter
#from scipy.misc import comb

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

ans = 0
for c,d in blue:
    x = []
    for a,b in red:
        if a < c and b < d:
            x.append([a,b])
    if len(x) > 0:
        ans += 1
        x = sorted(x, key=lambda x:x[1])
        red.remove(x[-1])

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

"""考え方
1.青色を第一要素（x）が小さい順にソートする
2.青色の点より左にある赤い点のうち、yが小さく、かつ一番大きい赤い点を選択する
"""

## 1.必要な配列を取得し、x軸でソートしておく
## 1-1.赤色
AB = []
for n in range(N):
  AB.append(list(map(int, input().split())))
  
AB = sorted(AB, key=lambda x: x[1], reverse=True)

## 1-2.青色
CD = []
for n in range(N):
  CD.append(list(map(int, input().split())))
CD = sorted(CD, key=lambda x: x[0], reverse=True)


## 2.青色の点について、左から順に取得していく
used_idx = []
ans = 0
for _ in CD:
  c = _[0]
  d = _[1]
  red_max_y = -1
  ## 左側にある赤色の要素を検索
  for idx, __ in enumerate(AB):
    a = __[0]
    b = __[1]
    if a < c:
      if b < d:
        if idx not in used_idx:
          used_idx.append(idx)
          ans += 1
          break
  
    
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
red = []
blue = []
B = [0]*(n+1)
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(key=lambda x: x[0])
blue.sort(key=lambda x: x[0])
cnt = 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]) and B[j+1] == 0:
      B[j+1] = 1
      cnt += 1
      break

print(cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
red = []
blue = []
B = [0]*(n+1)
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(key=lambda x: x[0])
blue.sort(key=lambda x: x[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]) and B[j+1] == 0:
      B[j+1] = 1
      break

print(sum(B))

Submission status: Wrong Answer

Solution code:
n=int(input())
r=[None]*n
b=[None]*n

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

used=[False for i in range(n)]
ans=0
for i in range(n):
  rx,ry=r[i][0],r[i][1]
  miny=10**10
  minj=-1
  for j in range(n):
    if used[j]:
      continue
    bx,by=b[j][0],b[j][1]
    if rx<bx and ry<by:
      if by<miny:
        miny=by
        minj=j
  if minj!=-1:
    used[minj]=True
    ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
r=[None]*n
b=[None]*n

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

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

used=[False for i in range(n)]
ans=0
for i in range(n):
  rx,ry=r[i][0],r[i][1]
  for j in range(n):
    if not used[j]:
      if rx<b[j][0] and ry<b[j][1]:
        ans+=1
        used[j]=True
        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.sort(key=lambda x:x[0], reverse=True)
red.sort(key=lambda x:x[1], reverse=True)
blue.sort(key=lambda x:x[0])
blue.sort(key=lambda x:x[1])
 
ans = 0
for i in range(N):
    a,b = red[i]
    for j in range(len(blue)):
        c,d = blue[j]
        if a < c and b < d:
            blue.pop(j)
            ans += 1
            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.sort(key=lambda x:x[0], reverse=True)
red.sort(key=lambda x:x[1], reverse=True)
blue.sort(key=lambda x:x[0])
blue.sort(key=lambda x:x[1])
 
ans = 0
for i in range(N):
    a,b = red[i]
    for j in range(len(blue)):
        c,d = blue[j]
        if a < c and b < d:
            print(a,b,c,d)
            blue.pop(j)
            ans += 1
            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.sort(key=lambda x:x[0],reverse=True)
blue.sort(key=lambda x:x[0])
blue.sort(key=lambda x:x[1])

ans = 0
for i in range(N):
    a,b = red[i]
    for j in range(len(blue)):
        c,d = blue[j]
        if a < c and b < d:
            print(a,b,c,d)
            blue.pop(j)
            ans += 1
            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.sort(key=lambda x:x[0],reverse=True)
blue.sort(key=lambda x:x[1])

ans = 0
for i in range(N):
    a,b = red[i]
    for j in range(len(blue)):
        c,d = blue[j]
        if a < c and b < d:
            print(a,b,c,d)
            blue.pop(j)
            ans += 1
            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.sort(key=lambda x:x[0],reverse=True)
red.sort(key=lambda x:x[1],reverse=True)
blue.sort(key=lambda x:x[0])
blue.sort(key=lambda x:x[1])

ans = 0
for i in range(N):
    a,b = red[i]
    for j in range(len(blue)):
        c,d = blue[j]
        if a < c and b < d:
            print(a,b,c,d)
            blue.pop(j)
            ans += 1
            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.sort(key=lambda x:x[0])
red.sort(key=lambda x:x[1])
blue.sort(key=lambda x:x[0])
blue.sort(key=lambda x:x[1])

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

Submission status: Wrong Answer

Solution code:
N=int(input())
r=[tuple(map(int,input().split())) for i in range(N)]
b=[tuple(map(int,input().split())) for i in range(N)]
r.sort()
b.sort()
a=0
for i in b:
    t=(-1,-1)
    for j in r:
        if j[0]>i[0]:
            break
        if t[1]<j[1]:
            t=j
    if t!=(-1,-1):
        r.remove(t)
        a+=1
print(a)

Submission status: Wrong Answer

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

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

ab.sort()
cd.sort(key=lambda x:x[1])
#print(ab,cd)
ans=0
for i in range(n):
    for j in range(len(cd)):
        if ab[i][0]<cd[j][0] and  ab[i][1]<cd[j][1] : 
            
            ans+=1
            cd.pop(j)
            #print(ab,cd)
            break
print(ans)

Submission status: Wrong Answer

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

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

ab.sort()
cd.sort()#key=lambda x:x[1])
#print(ab,cd)
ans=0
for i in range(n):
    for j in range(len(cd)):
        if ab[i][0]<cd[j][0] and  ab[i][1]<cd[j][1] : 
            
            ans+=1
            cd.pop(j)
            #print(ab,cd)
            break
print(ans)

Submission status: Wrong Answer

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

for i in range(n):
    ab.append([2]+list(map(int,input().split())))

ab.sort(key=lambda x:(x[1],x[2]))
count=0
ans=0
for i in range(n*2):
    if ab[i][0]==1:
        count+=1
    else:
        if 1<=count:
            count-=1
            ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
from math import ceil
from operator import itemgetter

def main():
    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 = itemgetter(0))
    AB.sort( key = itemgetter(1))
    CD.sort( key = itemgetter(0))
    CD.sort(key = itemgetter(1))

    ans = 0
    used = [False]*N
    for i in range(N):
        c,d = CD[i]
        for j in range(N):
            a,b = AB[N - j - 1]
            if not(used[N - j - 1]) and a <= c and b <= d:
                ans += 1
                used[N - j - 1] = True
                break
    print(ans)
    return

if __name__ == "__main__":
    main()

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)]
alr = [False for i in range(N)]
ab.sort()
cd.sort()
count = 0
for c,d in cd:
    maxi = -1
    for i in range(N):
        if alr[i]:
            continue
        a,b = ab[i][0],ab[i][1]
        if a < c:
            if b < d:
                maxi = max(maxi,i)
        else:
            break
    if maxi != -1:
        alr[maxi] = True
print(alr.count(True))

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)]
R.sort(key=lambda x:(-x[0],-x[1]))
B.sort()

ans = 0
for rx,ry in R:
    for bx,by in B:
        # print(rx,ry,bx,by)
        if rx<bx and ry<by:
            # print("ok")
            ans += 1
            B.remove([bx,by])
            break

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from operator import itemgetter

input = sys.stdin.readline


def main():
    N = int(input())
    AB = [[int(x) for x in input().split()] for _ in range(N)]
    CD = [[int(x) for x in input().split()] for _ in range(N)]

    ABS = sorted(AB, reverse=True)
    CDS = sorted(CD, reverse=True)

    ans = 0
    for a, b in ABS:
        for i, v in enumerate(CDS):
            if a <= v[0] and b <= v[1]:
                ans += 1
                CDS.pop(i)
                break

    ABS = sorted(AB, reverse=True, key=itemgetter(1))
    CDS = sorted(CD, reverse=True, key=itemgetter(1))

    ans1 = 0
    for a, b in ABS:
        for i, v in enumerate(CDS):
            if a <= v[0] and b <= v[1]:
                ans1 += 1
                CDS.pop(i)
                break

    print(max(ans, ans1))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
from operator import itemgetter

input = sys.stdin.readline


def main():
    N = int(input())
    AB = [[int(x) for x in input().split()] for _ in range(N)]
    CD = [[int(x) for x in input().split()] for _ in range(N)]

    ABS = sorted(AB)
    CDS = sorted(CD)

    ans = 0
    for a, b in ABS:
        for i, v in enumerate(CDS):
            if a <= v[0] and b <= v[1]:
                ans += 1
                CDS.pop(i)
                break

    ABS = sorted(AB, key=itemgetter(1))
    CDS = sorted(CD, key=itemgetter(1))

    ans1 = 0
    for a, b in ABS:
        for i, v in enumerate(CDS):
            if a <= v[0] and b <= v[1]:
                ans1 += 1
                CDS.pop(i)
                break

    print(max(ans, ans1))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:

Submission status: Wrong Answer

Solution code:
from operator import itemgetter

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=itemgetter(0),reverse = True)
B1 = sorted(B, key=itemgetter(0),reverse = True)
cnt = 0

for i in range(N): 
    for j in range(N):
        if (B1[i][0] > A1[j][0]) and (B1[i][1] > A1[j][1]):
            cnt+=1
            A1[j] = [500,500] #これがなかった
            #print(B1[i],A1[j])
            break #これがなかった
print(cnt)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter

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=itemgetter(0),reverse = True)
B1 = sorted(B, key=itemgetter(0),reverse = True)
cnt = 0

for i in range(N): 
    for j in range(N):
        if (B1[i][0] > A1[j][0]) and (B1[i][1] > A1[j][1]):
            cnt+=1
            A[j] = [500,500] #これがなかった
            #print(B1[i],A1[j])
            break #これがなかった
print(cnt)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter

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=itemgetter(0),reverse = True)
B1 = sorted(B, key=itemgetter(0),reverse = True)
cnt = 0

for i in range(N): 
    for j in range(N):
        if (B1[i][0] > A1[j][0]) and (B1[i][1] > A1[j][1]):
            cnt+=1
            #A[j] = [500,500] #これがなかった
            #print(B1[i],A1[j])
            break #これがなかった
print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
Red = [0] * N
Blue = [0] * N
for j in range(N):
    Red[j] = [0] * 2
    Red[j][0], Red[j][1] = map(int, input().split())
for k in range(N):
    Blue[k] = [0] * 2
    Blue[k][0], Blue[k][1] = map(int, input().split())
Blue = sorted(Blue)
Red = sorted(Red)
ans = 0
for i in range(N):
    kouho = -1
    blue_x = Blue[i][0]
    blue_y = Blue[i][1]
    kouho_y = -1
    for p in range(len(Red)):
        if blue_x > Red[p][0]:
            if kouho_y < Red[p][1]:
                kouho_y = Red[p][1]
                kouho = p
        else:
            continue
    if kouho >= 0:
        ans += 1
        del Red[kouho]

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
Red = [0] * N
Blue = [0] * N
for j in range(N):
    Red[j] = [0] * 2
    Red[j][0], Red[j][1] = map(int, input().split())
for k in range(N):
    Blue[k] = [0] * 2
    Blue[k][0], Blue[k][1] = map(int, input().split())
Blue = sorted(Blue)
Red = sorted(Red)
ans = 0
for i in range(N):
    kouho = -1
    blue_x = Blue[i][0]
    blue_y = Blue[i][1]
    kouho_y = -1
    for p in range(len(Red)):
        if blue_x > Red[p][0]:
            if kouho_y < Red[p][1]:
                kouho_y = Red[p][1]
                kouho = p
        else:
            break
    if kouho >= 0:
        ans += 1
        del Red[kouho]

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
Red = [0] * N
Blue = [0] * N
for j in range(N):
    Red[j] = [0] * 2
    Red[j][0], Red[j][1] = map(int, input().split())
for k in range(N):
    Blue[k] = [0] * 2
    Blue[k][0], Blue[k][1] = map(int, input().split())
Blue = sorted(Blue)
Red = sorted(Red)
ans = 0
for i in range(N):
    kouho = -1
    blue_x = Blue[i][0]
    blue_y = Blue[j][1]
    kouho_y = -1
    for p in range(len(Red)):
        if blue_x > Red[p][0]:
            if kouho_y < Red[p][1]:
                kouho_y = Red[p][1]
                kouho = p
        else:
            break
    if kouho >= 0:
        ans += 1
        del Red[kouho]

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
Red = [0] * N
Blue = [0] * N
for j in range(N):
    Red[j] = [0] * 2
    Red[j][0], Red[j][1] = map(int, input().split())
for k in range(N):
    Blue[k] = [0] * 2
    Blue[k][0], Blue[k][1] = map(int, input().split())
Blue = sorted(Blue)
Red = sorted(Red)
ans = 0
for i in range(N):
    kouho = -1
    blue_x = Blue[i][0]
    blue_y = Blue[j][1]
    kouho_y = -1
    for p in range(len(Red)):
        if blue_x > Red[p][0]:
            if kouho_y < Red[p][1]:
                kouho_y = Red[p][1]
                kouho = p
        else:
            break
        if kouho >= 0:
            ans += 1
            del Red[kouho]
            break
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)]
d,ans=dict(),0
for i in range(n):
  cnt=-1
  ok=False
  for j in range(n):
    if j not in d:
      if b[i][0]>r[j][0] and b[i][1]>r[j][1]:
        if r[j][1]>cnt:
          cnt=r[j][1]
          k=j
          ok=True
  if ok:
    ans+=1
    d[k]=0
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)]
d,ans=dict(),0
for i in range(n):
  cnt=-1
  ok=False
  for j in range(n):
    if j not in d:
      if b[i][0]>r[j][0]:
        if r[j][1]>cnt:
          cnt=r[j][1]
          k=j
          ok=True
  if ok:
    ans+=1
    d[k]=0
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)]
d,ans=dict(),0
for i in range(n):
  cnt=0
  ok=False
  for j in range(n):
    if j not in d:
      if b[i][0]>r[j][0]:
        if r[j][1]>=cnt:
          cnt=r[j][1]
          k=j
          ok=True
  if ok:
    ans+=1
    d[k]=0
print(ans)

Submission status: Wrong Answer

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

ans = 0
for i in range(N):
    a = ab[i][0]
    b = ab[i][1]
    for j in range(N):
        if cd[j][2] == True:
            continue 
        c = cd[j][0]
        d = cd[j][1]
        if a<c and b<d:
            ans += 1
            cd[j][2] = True
            break
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
red = []
blue = []
chosen = [0]*N
ans = 0
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[1])
blue.sort(key=lambda x:x[0])

for i in range(N):
  for j in range(N):
    if blue[i][0] >= red[j][0] and blue[i][1] >= red[j][1] and chosen[j] == 0:
      chosen[j] = 1
      ans += 1
      break
      
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
red = []
blue = []
chosen = [0]*N
ans = 0
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])
blue.sort(key=lambda x:x[1])

for i in range(N):
  for j in range(N):
    if red[i][0] <= blue[j][0] and red[i][1] <= blue[j][1] and chosen[j] == 0:
      chosen[j] = 1
      ans += 1
      break
      
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
red = []
blue = []
chosen = [0]*N
ans = 0
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[1])
blue.sort(key=lambda x:x[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] and chosen[j] == 0:
      chosen[j] = 1
      ans += 1
      break
      
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
red = []
blue = []
chosen = [0]*N
ans = 0
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[1])
red.sort(key=lambda x:x[0])
blue.sort(key=lambda x:x[1])
blue.sort(key=lambda x:x[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] and chosen[j] == 0:
      chosen[j] = 1
      ans += 1
      break
      
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
red = []
blue = []
chosen = [0]*N
ans = 0
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[1])
red.sort(key=lambda x:x[0])
blue.sort(key=lambda x:x[1])
blue.sort(key=lambda x:x[0])

for i in range(N):
  for j in range(N):
    if red[i][0] <= blue[j][0] and red[i][1] <= blue[j][0] and chosen[j] == 0:
      chosen[j] = 1
      ans += 1
      break
print(ans)

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):
  a, b = map(int, input().split())
  BLUE.append((a, b))

BLUE.sort(key=lambda x: x[0])
RED.sort(key=lambda x: -x[0] and -x[1])


red_selected = set()
blue_selected = set()
for i in range(N):
  c, d = BLUE[i]
  
  for j in range(N):
    a, b = RED[j]
    if a < c and b < d and j not in red_selected and i not in blue_selected:
      red_selected.add(j)
      blue_selected.add(i)

print(len(red_selected))

Submission status: Wrong Answer

Solution code:
from operator import itemgetter
from collections import deque

n = int(input())
ab = deque(sorted((list(map(int, input().split())) for _ in range(n)), key=itemgetter(1),reverse=True))
cd = sorted((list(map(int, input().split())) for _ in range(n)), key=itemgetter(0))
print(ab)
print(cd)
ans = 0
for i in range(n):
    for j in range(len(cd)):
        if ab[0][0] < cd[j][0] and ab[0][1] < cd[j][1]:
            ans += 1
            ab.popleft()
            cd.pop(j)
            break
    else:
        ab.popleft()

print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
from collections import defaultdict

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

m = defaultdict(set)
for i in range(n):
    for j in range(n):
        a,b = ab[i]
        c,d = cd[j]
        if a<c and b<d:
            m[i].add(j)

k = list(m.keys())
k.sort(key=lambda x:m[x])

used = set()
res = 0
for x in k:
    for u in m[x]:
        if u not in used:
            res += 1
            used.add(u)
            break
print(res)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter
from collections import deque

n = int(input())
ab = deque(sorted((list(map(int, input().split())) for _ in range(n)), key=itemgetter(0)))
cd = sorted((list(map(int, input().split())) for _ in range(n)), key=itemgetter(1))

ans = 0
for i in range(n):
    for j in range(len(cd)):
        if ab[0][0] < cd[j][0] and ab[0][1] < cd[j][1]:
            ans += 1
            ab.popleft()
            cd.pop(j)
            break
    else:
        ab.popleft()

print(ans)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter
from collections import deque

n = int(input())
ab_0 = (list(map(int, input().split())) for _ in range(n))
cd_0 = (list(map(int, input().split())) for _ in range(n))
ab_1 = deque(sorted(ab_0, key=itemgetter(0)))
ab_2 = deque(sorted(ab_1, key=itemgetter(1)))
cd_1 = sorted(cd_0, key=itemgetter(0))
cd_2 = sorted(cd_1, key=itemgetter(1))

def calc(ab, cd):

    ans = 0
    for i in range(n):
        for j in range(len(cd)):
            if ab[0][0] < cd[j][0] and ab[0][1] < cd[j][1]:
                ans += 1
                ab.popleft()
                cd.pop(j)
                break
        else:
            ab.popleft()

    return ans


print(max(calc(ab_1, cd_1), calc(ab_2, cd_2)))

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
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_x = sorted(ab, reverse=True, key=lambda x:x[0])
ab_y = sorted(ab, reverse=True, key=lambda x:x[1])
cd_x = sorted(cd, key=lambda x:x[0])
cd_y = sorted(cd, key=lambda x:x[1])
ans = 0
for i in ab_x:
    for j in cd_x:
        if i[0] < j[0] and i[1] < j[1]:
            ans += 1
            cd_x.remove(j)
            break
cnt = 0
for i in ab_y:
    for j in cd_y:
        if i[0] < j[0] and i[1] < j[1]:
            cnt += 1
            cd_y.remove(j)
            break
print(max(ans, cnt))

Submission status: Wrong Answer

Solution code:
N = int(input())
AB = [tuple(map(int, input().split())) for _ in range(N)]
AB.sort(reverse=True)
CD = [tuple(map(int, input().split())) for _ in range(N)]
CD.sort()
use = [False] * (N+1)
for a, b in AB:
    m = (10000, -1)
    for i, (c, d) in enumerate(CD):
        if a < c and b < d and not use[i]:
            m = min(m, (c+d-a-b, i))
    use[m[1]] = True
print(sum(use[:-1]))

Submission status: Wrong Answer

Solution code:
N = int(input())
AB = [tuple(map(int, input().split())) for _ in range(N)]
AB.sort(reverse=True)
CD = [tuple(map(int, input().split())) for _ in range(N)]
CD.sort(reverse=True)
use = [False] * (N+1)
for a, b in AB:
    m = (10000, -1)
    for i, (c, d) in enumerate(CD):
        if a < c and b < d and not use[i]:
            m = min(m, (c+d-a-b, i))
    use[m[1]] = True
print(sum(use[:-1]))

Submission status: Wrong Answer

Solution code:
# WIP
import sys
sys_input = sys.stdin.readline

N = int(sys_input())
red_points = [tuple(map(int, sys_input().split())) for p in range(N)]
red_points = sorted(red_points, key=lambda x: (x[0]**2 + x[1]**2)**0.5)
blue_points = [tuple(map(int, sys_input().split())) for p in range(N)]
blue_points = sorted(blue_points, key=lambda x: (x[0]**2 + x[1]**2)**0.5)

# Enumerate all combinations (with duplications)
# -> How to select non-duplicated pairs?
canditates = [[] for _ in range(N)]
for red in red_points:
    for i, blue in enumerate(blue_points):
        if red[0] < blue[0] and red[1] < blue[1]:
            canditates[i].append(red)


canditates = sorted(canditates, key=lambda x: len(x))
n_combi = 0
already_selected = []
for i, cand in enumerate(canditates[:N-1]):
    point_at_min_appear = None
    min_n_appear = N
    for point in cand:
        if point in already_selected:
            continue
        n_appear = 0
        for cand_ano in canditates[i+1:]:
            if point in cand_ano:
                n_appear += 1
        if min_n_appear > n_appear:
            point_at_min_appear = point
    
    if point_at_min_appear is not None:
        n_combi += 1
        already_selected.append(point_at_min_appear)

# last element
last_points = canditates[-1]
for point in last_points:
    if point not in already_selected:
        n_combi += 1
        break

print(n_combi)

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()
CD.sort()

#print(AB)
#print(CD)

li = [[] for i in range(N)]

for i in range(N):
    ab = AB[i]
    for j in range(N):
        cd = CD[j]
        if ab[0] < cd[0] and ab[1] < cd[1]:
            li[i].append(cd)

for i in range(N):
    li[i].sort(key=lambda x: x[0]+x[1])


#print(li)

newli = []
for i in range(N):
    if li[i] != []:
        newli.append(li[i])
    else:
        N -= 1

li = newli

ans = 0
while len(li) != 0:
    l = 1000
    
    for i in range(N):
        l = min(l,len(li[i]))

    numli = []
    for i in range(N):
        if len(li[i]) == l:
            numli.append(i)
    rem = li[numli[0]].pop(0)
    li.remove(li[numli[0]])
    N -= 1
    ans += 1

    for j in range(N):
        if rem in li[j]:
            li[j].remove(rem)

    newli = []
    for i in range(N):
        if li[i] != []:
            newli.append(li[i])
        else:
            N -= 1

    li = newli

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()
CD.sort()

#print(AB)
#print(CD)

li = [[] for i in range(N)]

for i in range(N):
    ab = AB[i]
    for j in range(N):
        cd = CD[j]
        if ab[0] < cd[0] and ab[1] < cd[1]:
            li[i].append(cd)

for i in range(N):
    li[i].sort(key=lambda x: x[1])


#print(li)

newli = []
for i in range(N):
    if li[i] != []:
        newli.append(li[i])
    else:
        N -= 1

li = newli

ans = 0
while len(li) != 0:
    l = 1000
    
    for i in range(N):
        l = min(l,len(li[i]))

    numli = []
    for i in range(N):
        if len(li[i]) == l:
            numli.append(i)
    rem = li[numli[0]].pop(0)
    li.remove(li[numli[0]])
    N -= 1
    ans += 1

    for j in range(N):
        if rem in li[j]:
            li[j].remove(rem)

    newli = []
    for i in range(N):
        if li[i] != []:
            newli.append(li[i])
        else:
            N -= 1

    li = newli

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()
CD.sort()

#print(AB)
#print(CD)

li = [[] for i in range(N)]

for i in range(N):
    ab = AB[i]
    for j in range(N):
        cd = CD[j]
        if ab[0] < cd[0] and ab[1] < cd[1]:
            li[i].append(cd)

for i in range(N):
    li[i].sort(key=lambda x: x[1])


#print(li)

newli = []
for i in range(N):
    if li[i] != []:
        newli.append(li[i])
    else:
        N -= 1

li = newli

ans = 0
while len(li) != 0:
    l = 1000
    
    for i in range(N):
        l = min(l,len(li[i]))

    numli = []
    for i in range(N):
        if len(li[i]) == l:
            numli.append(i)
    rem = li[numli[-1]].pop()
    li.remove(li[numli[-1]])
    N -= 1
    ans += 1

    for j in range(N):
        if rem in li[j]:
            li[j].remove(rem)

    newli = []
    for i in range(N):
        if li[i] != []:
            newli.append(li[i])
        else:
            N -= 1

    li = newli

print(ans)