Problem:


Score : 400 points

Problem Statement

On a two-dimensional plane, there are N red points and N blue points.
The coordinates of the i-th red point are (a_i, b_i), and the coordinates of the i-th blue point are (c_i, d_i).

A red point and a blue point can form a friendly pair when, the x-coordinate of the red point is smaller than that of the blue point, and the y-coordinate of the red point is also smaller than that of the blue point.

At most how many friendly pairs can you form? Note that a point cannot belong to multiple pairs.

Constraints

All input values are integers.

1 \leq N \leq 100

0 \leq a_i, b_i, c_i, d_i < 2N

a_1, a_2, ..., a_N, c_1, c_2, ..., c_N are all different.

b_1, b_2, ..., b_N, d_1, d_2, ..., d_N are all different.

Input

Input is given from Standard Input in the following format:

N
a_1 b_1
a_2 b_2
:
a_N b_N
c_1 d_1
c_2 d_2
:
c_N d_N

Output

Print the maximum number of friendly pairs.

Sample Input 1

3
2 0
3 1
1 3
4 2
0 4
5 5

Sample Output 1

2

For example, you can pair (2, 0) and (4, 2), then (3, 1) and (5, 5).

Sample Input 2

3
0 0
1 1
5 2
2 3
3 4
4 5

Sample Output 2

2

For example, you can pair (0, 0) and (2, 3), then (1, 1) and (3, 4).

Sample Input 3

2
2 2
3 3
0 0
1 1

Sample Output 3

0

It is possible that no pair can be formed.

Sample Input 4

5
0 0
7 3
2 2
4 8
1 6
8 5
6 9
5 4
9 1
3 7

Sample Output 4

5

Sample Input 5

5
0 0
1 1
5 5
6 6
7 7
2 2
3 3
4 4
8 8
9 9

Sample Output 5

4



Sample input:
3
2 0
3 1
1 3
4 2
0 4
5 5


Sample output:
2

Submission status: Wrong Answer

Solution code:
n=int(input())

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

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

ab.sort()
cd.sort()
cnt=0
for item1 in cd:
  x,y=item1[0],item1[1]
  result=[]
  for item2 in ab:
    xx,yy=item2[0],item2[1]
    if x>xx and y>yy:
      if result==[]:
        result=[xx,yy]
      else:
        if yy<result[1]:
          result=[xx,yy]
  if result!=[]:
    ab.remove((xx,yy))
    cnt+=1
print(cnt)

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

grid = [[0] * n for i in range(n)]
for i in range(n):
    for j in range(n):
        a, b = ab[i]
        c, d = cd[j]
        if a < c and b < d:
            grid[i][j] = 1

cnt0 = 0
cnt1 = 0
flag0 = 0
flag1 = 0
for i in range(n):
    for j in range(n):
        temp0 = grid[j][i]
        temp1 = grid[i][j]
        flag0 = flag0|temp0
        flag1 = flag1|temp1
    if flag0 == 1:cnt0 += 1
    if flag1 == 1:cnt1 += 1
    flag0 = 0
    flag1 = 0

print(min(cnt0, cnt1))

Submission status: Wrong Answer

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

B = []
for _ in range(N):
  x,y = list(map(int, input().split()))
  B.append((x,y))

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

for bx,by in B:
  can = None
  for i in range(len(A)):
    if A[i][0] < bx and A[i][1] < by:
      can = i
      break

  if can is not None:
    cnt += 1

print(cnt)

Submission status: Wrong Answer

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

B = []
for _ in range(N):
  x,y = list(map(int, input().split()))
  B.append((x,y))

A = sorted(A, key=lambda x: (x[1]+1)/(x[0]+1))
B = sorted(B, key=lambda x: (x[1]+1)/(x[0]+1))
cnt = 0

for ax,ay in A:
  for i in range(len(B)):
    bx,by = B[i]
    if ax < bx and ay < by:
      B.pop(i)
      cnt += 1
      break

print(cnt)

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


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

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

    reds.sort(key=lambda x: x[0])
    blues.sort(key=lambda x: x[0])
    used = [False] * N

    ans = 0
    for i in range(N)[::-1]:
        b = blues[i]
        max_r = -1
        max_j = None
        for j in range(N):
            r = reds[j]
            if b[0] < r[0]:
                continue
            if b[1] < r[1]:
                continue

            if not used[j] and max_r < r[1]:
                max_r = r[1]
                max_j = j

        if max_j is not None:
            used[max_j] = True
            ans += 1

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


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

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

    reds.sort(key=lambda x: x[0])
    blues.sort(key=lambda x: x[0])
    used = [False] * N

    ans = 0
    for i in range(N):
        min_y = INF
        min_j = None
        for j in range(N):
            if reds[i][0] > blues[j][0]:
                continue

            if reds[i][1] > blues[j][1]:
                continue

            if not used[j] and min_y > blues[j][1]:
                min_y = blues[j][1]
                min_j = j

        if min_j is not None:
            used[min_j] = True
            ans += 1

    print(ans)


if __name__ == "__main__":
    main()

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])
ans=0
red.sort(reverse=True)
blue.sort(reverse=True)
chr=[False]*n
chb=[False]*n
for i in range(n):
    for j in range(n):
        if chr[i]!=True and chb[j]!=True and red[i][0]<=blue[j][0] and red[i][1]<=blue[j][1]:
            ans+=1
            chr[i]=True
            chb[j]=True

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
R = []
B = []
R_tmp = []
for _ in range(N):
    a,b = map(int,input().split())
    R_tmp.append(a)
    R.append([a,b])

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

B = sorted(B)
R = sorted(R)
R_tmp.sort()
from bisect import bisect_left
ans = 0
for x in B:
    index = bisect_left(R_tmp,x[0])
    tmp = R[:index]
    tmp = sorted(tmp)
    for i in range(index)[::-1]:
        if tmp[i][1] < x[1]:
            R.remove([tmp[i][0],tmp[i][1]])
            R_tmp.remove(tmp[i][0])
            ans += 1
            break
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
R = []
B = []
R_tmp = []
for _ in range(N):
    a,b = map(int,input().split())
    R_tmp.append(a)
    R.append([a,b])

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

B = sorted(B)
R = sorted(R)
R_tmp.sort()
from bisect import bisect_left
ans = 0
for x in B[::-1]:
    index = bisect_left(R_tmp,x[0])
    tmp = R[:index]
    tmp = sorted(tmp)
    for i in range(index)[::-1]:
        if tmp[i][1] < x[1]:
            R.remove([tmp[i][0],tmp[i][1]])
            R_tmp.remove(tmp[i][0])
            ans += 1
            break
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
R = []
B = []
R_tmp = []
for _ in range(N):
    a,b = map(int,input().split())
    R_tmp.append(a)
    R.append([a,b])

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

B = sorted(B)
R = sorted(R)
R_tmp.sort()
from bisect import bisect_left
ans = 0
for x in B[::-1]:
    index = bisect_left(R_tmp,x[0])
    tmp = R[:index]
    tmp = sorted(tmp, key=lambda x:x[1])
    for i in range(index)[::-1]:
        if tmp[i][1] < x[1]:
            R.remove([tmp[i][0],tmp[i][1]])
            R_tmp.remove(tmp[i][0])
            ans += 1
            break
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
R = []
B = []
R_tmp = []
for _ in range(N):
    a,b = map(int,input().split())
    R_tmp.append(a)
    R.append([a,b])

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

B = sorted(B)
R = sorted(R)
R_tmp.sort()
from bisect import bisect_left
ans = 0
for x in B[::-1]:
    index = bisect_left(R_tmp,x[0])
    for i in range(index)[::-1]:
        if R[i][1] < x[1]:
            R.pop(i)
            R_tmp.pop(i)
            ans += 1
            break
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
R = []
B = []
R_tmp = []
for _ in range(N):
    a,b = map(int,input().split())
    R_tmp.append(a)
    R.append([a,b])

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

B = sorted(B)
R = sorted(R)
R_tmp.sort()
from bisect import bisect_right
ans = 0
for x in B[::-1]:
    index = bisect_right(R_tmp,x[0])
    for i in range(index)[::-1]:
        if R[i][1] < x[1]:
            R.pop(i)
            R_tmp.pop(i)
            ans += 1
            break
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
R = []
B = []
R_tmp = []
for _ in range(N):
    a,b = map(int,input().split())
    R_tmp.append(a)
    R.append([a,b])

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

B = sorted(B)
R = sorted(R)
R_tmp.sort()
from bisect import bisect_right
ans = 0
for x in B:
    index = bisect_right(R_tmp,x[0])
    for i in range(index)[::-1]:
        if R[i][1] < x[1]:
            R.pop(i)
            R_tmp.pop(i)
            ans += 1
            break
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque
sys.setrecursionlimit(1000000) # 再帰上限を増やす

def main():
    input = sys.stdin.readline  # 文字列に対してinputした場合は、rstripするのを忘れずに！
    N = int(input())
    red = []
    for _ in range(N):
        a, b = map(int, input().rstrip().split())
        red.append((a, b, a*b))
    blue = []
    for _ in range(N):
        c, d = map(int, input().rstrip().split())
        blue.append((c, d, c*d))
    red.sort(key=lambda x:x[2])
    blue.sort(key=lambda x:x[2])
    count = 0
    blue = deque(blue)
    for r in red:
        while blue:
            b = blue.popleft()
            if r[0] < b[0] and r[1] < b[1]:
                count += 1
                break
    print(count)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
a = []
b = []
for i in range(n):
    A,B = map(int,input().split())
    a.append((A,B))
for i in range(n):
    A,B = map(int,input().split())
    b.append((A,B))
a = sorted(a,key = lambda x : x[0] + x[1])
b = sorted(b,key = lambda x : x[0] + x[1])
usea = [False]*n
useb = [False]*n
ans = 0
for i in range(n):
    if usea[i]:
        continue
    for j in range(n):
        if useb[j]:
            continue
        if a[i][0] <= b[j][0] and a[i][1] <= b[j][1]:
            #print(a[i][0],b[j][0],a[i][1],b[j][1])
            ans += 1
            useb[j] = True
            usea[i] = True
            break
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, key=lambda x: x[1])
blue.sort()

ans = 0
for i in range(n):
    c, d = blue[i]
    for j in range(len(red)):
        a, b = red[j]
        if a < c:
            del red[j]
            ans += 1
            break

print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
ab=[map(int,input().split()) for i in range (N)]
a, b = [list(j) for j in zip(*ab)]
cd=[map(int,input().split()) for i in range (N)]
c, d = [list(j) for j in zip(*cd)]
from operator import itemgetter
pair_ab=[]
pair_cd=[]
for i in range(N):
  pair_parts_ab = [a[i], b[i]]
  pair_ab.append(pair_parts_ab)
for i in range(N):
  pair_parts_cd = [c[i], d[i]]
  pair_cd.append(pair_parts_cd)
pair_ab.sort(reverse=True)
pair_cd.sort(reverse=True)

count=0

for i in range(N):
  for j in range(len(pair_ab)):
    if (pair_cd[i][0]>pair_ab[j][0]) and (pair_cd[i][1]>pair_ab[j][1]):
        count+=1
        pair_ab.remove(pair_ab[j])
        break   
print(count)

Submission status: Wrong Answer

Solution code:
N=int(input())
ab=[map(int,input().split()) for i in range (N)]
a, b = [list(j) for j in zip(*ab)]
cd=[map(int,input().split()) for i in range (N)]
c, d = [list(j) for j in zip(*cd)]
from operator import itemgetter
pair_ab=[]
pair_cd=[]
for i in range(N):
  pair_parts_ab = [a[i], b[i]]
  pair_ab.append(pair_parts_ab)
for i in range(N):
  pair_parts_cd = [c[i], d[i]]
  pair_cd.append(pair_parts_cd)
pair_ab2 = sorted(pair_ab, key = itemgetter(0),reverse=True)
pair_cd2 = sorted(pair_cd, key = itemgetter(0),reverse=True)

count=0

for i in range(N):
  for j in range(len(pair_ab2)):
    if (pair_cd2[i][0]>pair_ab2[j][0]) and (pair_cd2[i][1]>pair_ab2[j][1]):
        count+=1
        t = sorted(pair_ab2, key=itemgetter(1))[-1]
        pair_ab2.remove(t)
        break

print(count)

Submission status: Wrong Answer

Solution code:
N=int(input())
ab=[map(int,input().split()) for i in range (N)]
a, b = [list(j) for j in zip(*ab)]
cd=[map(int,input().split()) for i in range (N)]
c, d = [list(j) for j in zip(*cd)]
from operator import itemgetter
pair_ab=[]
pair_cd=[]
for i in range(N):
  pair_parts_ab = [a[i], b[i]]
  pair_ab.append(pair_parts_ab)
for i in range(N):
  pair_parts_cd = [c[i], d[i]]
  pair_cd.append(pair_parts_cd)
pair_ab2 = sorted(pair_ab, key = itemgetter(0),reverse=True)
pair_cd2 = sorted(pair_cd, key = itemgetter(0),reverse=True)

count=0

for i in range(N):
  for j in range(len(pair_ab2)):
    if (pair_cd2[i][0]>pair_ab2[j][0]) and (pair_cd2[i][1]>pair_ab2[j][1]):
        count+=1
        del pair_ab2[j]
        break

print(count)

Submission status: Wrong Answer

Solution code:
N=int(input())
ab=[map(int,input().split()) for i in range (N)]
a, b = [list(j) for j in zip(*ab)]
cd=[map(int,input().split()) for i in range (N)]
c, d = [list(j) for j in zip(*cd)]
from operator import itemgetter
pair_ab=[]
pair_cd=[]
for i in range(N):
  pair_parts_ab = [a[i], b[i]]
  pair_ab.append(pair_parts_ab)
for i in range(N):
  pair_parts_cd = [c[i], d[i]]
  pair_cd.append(pair_parts_cd)
sorted(pair_cd, key = itemgetter(0),reverse=True)
sorted(pair_ab, key = itemgetter(0),reverse=True)
count=0
for i in range(N):
  for j in range(len(pair_ab)):
    if (pair_cd[i][0]>pair_ab[j][0]) and (pair_cd[i][1]>pair_ab[j][1]):
        count+=1
        del pair_ab[j]
        break
print(count)

Submission status: Wrong Answer

Solution code:
N=int(input())
ab=[map(int,input().split()) for i in range (N)]
a, b = [list(j) for j in zip(*ab)]
cd=[map(int,input().split()) for i in range (N)]
c, d = [list(j) for j in zip(*cd)]
pair_ab=[]
pair_cd=[]
for i in range(N):
  pair_parts_ab = [a[i], b[i]]
  pair_ab.append(pair_parts_ab)
for i in range(N):
  pair_parts_cd = [c[i], d[i]]
  pair_ab.append(pair_parts_cd)
count=0
for i in range(N):
  for j in range(N):
    if (c[i]>pair_ab[j][0]) and (d[i]>pair_ab[j][1]):
        count+=1
        break
print(count)

Submission status: Wrong Answer

Solution code:
N=int(input())
ab=[map(int,input().split()) for i in range (N)]
a, b = [list(j) for j in zip(*ab)]
cd=[map(int,input().split()) for i in range (N)]
c, d = [list(j) for j in zip(*cd)]
pair_ab=[]
pair_cd=[]
for i in range(N):
  pair_parts_ab = [a[i], b[i]]
  pair_ab.append(pair_parts_ab)
for i in range(N):
  pair_parts_cd = [c[i], d[i]]
  pair_ab.append(pair_parts_cd)
count=0
for i in range(N):
  if (c[i]>pair_ab[i][0]) and (d[i]>pair_ab[i][1]):
        count+=1
print(count)

Submission status: Wrong Answer

Solution code:
N=int(input())
ab=[map(int,input().split()) for i in range (N)]
a, b = [list(j) for j in zip(*ab)]
cd=[map(int,input().split()) for i in range (N)]
c, d = [list(j) for j in zip(*cd)]
pair_ab=[]
pair_cd=[]
for i in range(N):
  pair_parts_ab = [a[i], b[i]]
  pair_ab.append(pair_parts_ab)
for i in range(N):
  pair_parts_cd = [c[i], d[i]]
  pair_ab.append(pair_parts_cd)
count=0

for i in range(N):
  if (c[i]>pair_ab[i][0]) and (d[i]>pair_ab[i][1]):
        count+=1
print(count)

Submission status: Wrong Answer

Solution code:
N=int(input())
ab=[map(int,input().split()) for i in range (N)]
a, b = [list(j) for j in zip(*ab)]
cd=[map(int,input().split()) for i in range (N)]
c, d = [list(j) for j in zip(*cd)]
pair_ab=[]
pair_cd=[]
for i in range(N):
  pair_parts_ab = [a[i], b[i]]
  pair_ab.append(pair_parts_ab)
for i in range(N):
  pair_parts_cd = [c[i], d[i]]
  pair_ab.append(pair_parts_cd)
count=0
for i in range(N):
  for j in pair_ab:
     if (c[i]>j[0]) and (d[i]>j[1]):
        count+=1
        break
print(count)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter
from collections import deque
 
N = int(input())
R = [tuple(map(int, input().split())) for _ in range(N)]
B = [tuple(map(int, input().split())) for _ in range(N)]
 
R0 = sorted(R, key=itemgetter(0))
R1 = sorted(R, key=itemgetter(1))
B0 = sorted(B, key=itemgetter(0))
B1 = sorted(B, key=itemgetter(1))
 
R0_que = deque(R0)
R1_que = deque(R1)
B0_que = deque(B0)
B1_que = deque(B1)
 
count0 = 0
while B0_que:
    b = B0_que.popleft()
    while R0_que:
        r = R0_que.popleft()
        if (r[0] < b[0]) & (r[1] < b[1]):
            count0 += 1
            break

count1 = 0
while B1_que:
    b = B1_que.popleft()
    while R1_que:
        r = R1_que.popleft()
        if (r[0] < b[0]) & (r[1] < b[1]):
            count1 += 1
            break
print(max(count0, count1))

Submission status: Wrong Answer

Solution code:
from operator import itemgetter

N = int(input())
R = [tuple(map(int, input().split())) for _ in range(N)]
B = [tuple(map(int, input().split())) for _ in range(N)]
R = sorted(R, key=itemgetter(0))
B = sorted(B, key=itemgetter(0))

count = 0
for c, d in B:
    for a, b in R:
        if (a < c) & (b < d):
            count += 1
            R.remove((a, b))
            break
print(count)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter

N = int(input())
R = [tuple(map(int, input().split())) for _ in range(N)]
B = [tuple(map(int, input().split())) for _ in range(N)]
R = sorted(R, key=itemgetter(1))
B = sorted(B, key=itemgetter(0))

count = 0
for c, d in B:
    for a, b in R:
        if (a < c) & (b < d):
            count += 1
            R.remove((a, b))
            break
print(count)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter
from collections import deque

N = int(input())
R = [tuple(map(int, input().split())) for _ in range(N)]
B = [tuple(map(int, input().split())) for _ in range(N)]
R = sorted(R, key=itemgetter(1), reverse=True)
B = sorted(B, key=itemgetter(0))
R_que = deque(R)
B_que = deque(B)

count = 0
while R_que:
    r = R_que.popleft()
    while B_que:
        b = B_que.popleft()
        if (r[0] < b[0]) & (r[1] < b[1]):
            count += 1
            break

print(count)

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)
 
n = int(readline())
ab = [list(map(int, readline().split())) for _ in range(n)]
cd = [list(map(int, readline().split())) for _ in range(n)]
cd.sort()
cnt = 0
for c, d in cd:
    memo = []
    for i, (a, b) in enumerate(ab):
        if c > a and d > b:
            memo.append([i, b])
            cnt += 1

print(cnt)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter
from collections import deque
import numpy as np

N = int(input())
R = [tuple(map(int, input().split())) for _ in range(N)]
B = [tuple(map(int, input().split())) for _ in range(N)]
R = sorted(R, key=itemgetter(0))
B = sorted(B, key=itemgetter(0))
A = np.zeros((N, N))

for i in range(N):
    b = B[i]
    for j in range(N):
        r = R[j]
        if (b[0] > r[0]) & (b[1] > r[1]):
            A[i, j] = 1
        else:
            A[i, j] = 0

count = 0
for i in range(N):
    diag_sum = sum(np.diag(A, k=i)) + sum(np.diag(A, k=i-N))
    count = max(count, diag_sum)

print(int(count))

Submission status: Wrong Answer

Solution code:
from operator import itemgetter
from collections import deque

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

R0 = sorted(R, key=itemgetter(0,1))
R1 = sorted(R, key=itemgetter(1,0))
B0 = sorted(B, key=itemgetter(0,1))
B1 = sorted(B, key=itemgetter(1,0))

R0_que = deque(R0)
R1_que = deque(R1)
B0_que = deque(B0)
B1_que = deque(B1)

count0 = 0
while R0_que:
    r = R0_que.popleft()
    while B0_que:
        b = B0_que.popleft()
        if (r[0] < b[0]) & (r[1] < b[1]):
            count0 += 1
            break

count1 = 0
while R1_que:
    r = R1_que.popleft()
    while B1_que:
        b = B1_que.popleft()
        if (r[0] < b[0]) & (r[1] < b[1]):
            count1 += 1
            break
print(max(count0, count1))

Submission status: Wrong Answer

Solution code:
from operator import itemgetter
from collections import deque

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

R0 = sorted(R, key=itemgetter(0))
R1 = sorted(R, key=itemgetter(1))
B0 = sorted(B, key=itemgetter(0))
B1 = sorted(B, key=itemgetter(1))

R0_que = deque(R0)
R1_que = deque(R1)
B0_que = deque(B0)
B1_que = deque(B1)

count0 = 0
while R0_que:
    r = R0_que.popleft()
    while B0_que:
        b = B0_que.popleft()
        if (r[0] < b[0]) & (r[1] < b[1]):
            count0 += 1
            break

count1 = 0
while R1_que:
    r = R1_que.popleft()
    while B1_que:
        b = B1_que.popleft()
        if (r[0] < b[0]) & (r[1] < b[1]):
            count1 += 1
            break
print(max(count0, count1))

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
    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()
    blue.sort(key=lambda x: x[1])
    used = []

    for c,d in blue:
        for i in range(n):
            a, b = red[i][0], red[i][1]
            if a < c and b < d:
                if i not in used:
                    used.append(i)
                    break
    print(len(used))

Submission status: Wrong Answer

Solution code:
import sys
readline = sys.stdin.readline

def main():
    N = int(readline())
    R = [tuple(map(int, readline().rstrip().split())) for _ in range(N)]
    B = [tuple(map(int, readline().rstrip().split())) for _ in range(N)]

    mat = [[False] * N for _ in range(N)]
    ans = 0
    for i, (a, b) in enumerate(R):
        for j, (c, d) in enumerate(B):
            if a < c and b < d:
                mat[i][j] = True

    flg = [False] * N
    for cnt in range(1, N+1):
        for l in mat:
            if sum(l) == cnt:
                for i, b in enumerate(l):
                    if b and not flg[i]:
                        flg[i] = True
                        break

    print(sum(flg))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())

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

cnt_ab = [0]*n
cnt_cd = [0]*n

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_ab[i] = 1
            cnt_cd[j] = 1

print(min(cnt_ab.count(1), cnt_cd.count(1)))

Submission status: Wrong Answer

Solution code:
    #できなかった
n=int(input())
r=sorted([list(map(int,input().split())) for i in range(n)])
b=sorted([list(map(int,input().split())) for i in range(n)])
ans=0
for bx,by in b:
    index=-1
    ypoint=-1
    for num,(rx,ry) in enumerate(r):
        if bx>rx and by>ry and ypoint < ry:
            ypoint=ry
            index =num
        if ypoint>=0:
            ans+=1
            r.pop(index)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n = int(readline())
ab = [list(map(int, readline().split())) for _ in range(n)]
cd = [list(map(int, readline().split())) for _ in range(n)]
cnt = 0
for c, d in cd:
    memo = []
    for a, b in ab:
        if c > a and d > b:
            memo.append([a, b, a + b])
    if memo:
        cnt += 1
        memo.sort(key=lambda x: -x[2])
        ab.remove(memo[0][:2])
print(cnt)

Submission status: Wrong Answer

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

for c,d in B:
  i,mv,mi=0,-1,0
  for a,b in R:
    if a<c:
      if b<d and U[i]==0:
        if mv<d:
          mv,mi=d,i
      i+=1
    else:
      break

  if mv!=-1:
    U[mi]=1

print(sum(U))

Submission status: Wrong Answer

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

c,i=0,N-1
for a,b in reversed(B):
  while i>0 and R[i][0]>=a:
    i-=1
  if i==0:
    break

  j=i
  while j>=0 and (U[j]==1 or R[j][1]>=b):
    j-=1
  if j>=0 and U[j]==0 and R[j][1]<b:
    U[j]=1
    c+=1

print(c)

Submission status: Wrong Answer

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

c,i=0,N-1
for a,b in reversed(B):
  while i>0 and R[i][0]>=a:
    i-=1
  if i==0:
    break

  j=i
  while j>0 and (U[j]==1 or R[j][1]>=b):
    j-=1
  if j>=0 and U[j]==0 and R[j][1]<b:
    U[j]=1
    c+=1

print(c)

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, a ** 2 + b ** 2))
for i in range(N):
    c, d = map(int, input().split())
    Blue.append((c, d, c ** 2 + d ** 2))
Red.sort(key=lambda x: x[2], reverse=True)
Blue.sort(key=lambda x: x[2], reverse=True)

ans = 0
for i, j, z in Red:
    for k in range(len(Blue)):
        if Blue[k][0] <= i:
            continue
        elif Blue[k][0] > i:
            if Blue[k][1] > j:
                Blue.pop(k)
                ans += 1
                break

print(ans)

Submission status: Wrong Answer

Solution code:
import math, sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from copy import deepcopy
from functools import lru_cache
from heapq import heapify, heappop, heappush
from itertools import accumulate, combinations, permutations
input = sys.stdin.readline
mod = 10**9 + 7
ns = lambda: input().strip()
ni = lambda: int(input().strip())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

def main():
    n = ni()
    red = []
    for _ in range(n):
        red.append(nl())
    blue = []
    for _ in range(n):
        blue.append(nl())

    red.sort(key=lambda x:x[1], reverse=True)
    blue.sort(key=lambda x:x[0], reverse=True)

    #print(red, blue)
    ans = 0
    for _ in range(n):
        mn = blue.pop()
        for i in range(len(red)):
            if mn[0] > red[i][0] and mn[1] > red[i][1]:
                #print(mn, red.pop(i), 'pair')
                ans += 1
                break

    print(ans)
        

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math, sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from copy import deepcopy
from functools import lru_cache
from heapq import heapify, heappop, heappush
from itertools import accumulate, combinations, permutations
input = sys.stdin.readline
mod = 10**9 + 7
ns = lambda: input().strip()
ni = lambda: int(input().strip())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

def main():
    n = ni()
    red = []
    for _ in range(n):
        red.append(nl())
    blue = []
    for _ in range(n):
        blue.append(nl())

    red.sort(key=lambda x:x[1], reverse=True)
    blue.sort(key=lambda x:x[0], reverse=True)

    ans = 0
    for _ in range(n):
        mn = blue.pop()[1]
        for i in range(len(red)):
            if mn > red[i][0]:
                red.pop(i)
                ans += 1
                break

    print(ans)
        

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math, sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from copy import deepcopy
from functools import lru_cache
from heapq import heapify, heappop, heappush
from itertools import accumulate, combinations, permutations
input = sys.stdin.readline
mod = 10**9 + 7
ns = lambda: input().strip()
ni = lambda: int(input().strip())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

def main():
    n = ni()
    red = []
    for _ in range(n):
        red.append(nl())
    blue = []
    for _ in range(n):
        blue.append(nl())

    red.sort(key=lambda x:x[1], reverse=True)
    blue.sort(key=lambda x:x[0], reverse=True)

    ans = 0
    for _ in range(n):
        mn = blue.pop()[0]
        for i in range(len(red)):
            if mn > red[i][0]:
                red.pop(i)
                ans += 1
                break

    print(ans)
        

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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

    used = []
    for i in range(n):
        tmp = []
        for j in range(n):
            if not (R[j] in used) and (R[j][0] < B[i][0]) and R[j][1] < B[i][1]:
                used.append(R[j])
                break
    print(len(used))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from operator import itemgetter

n = int(input())
ab = [list(map(int, input().split())) for _ in range(n)]
cd = [list(map(int, input().split())) for _ in range(n)]
ans = 0
dp_ab = [False] * n
dp_cd = [False] * n

ab.sort(key = itemgetter(1), reverse = True)
cd.sort()

for i in range(n):
    count = 0
    for j in range(n):
        if cd[i][0] > ab[j][0] and cd[i][1] > ab[j][1]:
            count += 1
    cd[i].append(count)

cd.sort(key = itemgetter(2))

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

ab.sort(key = itemgetter(2))

for i in range(n):
    for j in range(n):
        if cd[i][0] > ab[j][0] and cd[i][1] > ab[j][1] and dp_cd[i] == False and dp_ab[j] == False:
            dp_cd[i] = True
            dp_ab[j] = True
            ans += 1

print(ans)