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

Submission status: Wrong Answer

Solution code:
n = int(input())
r = [ list(map(int,input().split())) for i in range(n)]
b = [ list(map(int,input().split())) for i in range(n)]
b.sort()
ans = 0
for i in range(n):
    Bx = b[i][0]
    By = b[i][1]
    tmp = [[10**6]]
    for j in range(len(r)):
        if r[j][0] <= Bx and r[j][1] <= By:
            dis = (Bx - r[j][0])**2 + (By - r[j][1])**2
            tmp.append([dis,j])
    if tmp[-1] == [10**6]:
        continue
    else:
        tmp.sort()
        ans += 1
        del r[tmp[0][1]]
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

red = []
blue = []

for i in range(N):
    red.append(list(map(int, input().split())))

for i in range(N):
    blue.append(list(map(int, input().split())))

rx = sorted(red, key=lambda x: x[0])
ry = sorted(red, key=lambda x: x[1])
bx = sorted(blue, key=lambda x: x[0])
by = sorted(blue, key=lambda x: x[1])

# xでソートしたときのペア
ans_x = 0
idx = 0
for i in range(N):

    while idx != N and (rx[i][0] >= bx[idx][0] or rx[i][1] >= bx[idx][1]):
        idx += 1
        
    if idx == N:
        break
    
    ans_x += 1
    idx += 1

# yでソートしたときのペア
ans_y = 0
idx = 0
for i in range(N):


    while idx != N and(ry[i][0] >= by[idx][0] or ry[i][1] >= by[idx][1]):
        idx += 1

    if idx == N:
        break

    ans_y += 1
    idx += 1

print(max(ans_x, ans_y))

Submission status: Wrong Answer

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

ans=0
for i in range(2*n):
    now = 2*n -1 -i
    for redpoint in red:
        if redpoint[0] == now:
            value=300
            add=[]
            for bid,bluepoint in enumerate(blue):
                if (bluepoint[0]>redpoint[0])and(bluepoint[1]>redpoint[1]):
                    if value>bluepoint[1]:
                        value =bluepoint[1]
                        add =bluepoint
            if add:
                blue.pop(blue.index(add))
                ans +=1
            if redpoint[0]==redpoint[1] and add:
                break
        if redpoint[1] == now:
            value=300
            add=[]
            for bid,bluepoint in enumerate(blue):
                if (bluepoint[0]>redpoint[0])and(bluepoint[1]>redpoint[1]):
                    if value>bluepoint[0]:
                        value =bluepoint[0]
                        add =bluepoint
            if add:
                blue.pop(blue.index(add))
                ans +=1
                        
print(ans)

Submission status: Wrong Answer

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

ans=0
for i in range(2*n):
    now = 2*n -1 -i
    for redpoint in red:
        if redpoint[0] == now:
            value=300
            add=[]
            for bid,bluepoint in enumerate(blue):
                if (bluepoint[0]>redpoint[0])and(bluepoint[1]>redpoint[1]):
                    if value>bluepoint[1]:
                        value =bluepoint[1]
                        add =bluepoint
            if add:
                blue.pop(blue.index(add))
                ans +=1
            if redpoint[0]==redpoint[1] and add:
                break
        if redpoint[1] == now:
            value=300
            add=[]
            for bid,bluepoint in enumerate(blue):
                if (bluepoint[0]>redpoint[0])and(bluepoint[1]>redpoint[1]):
                    if value>bluepoint[0]:
                        value =bluepoint[0]
                        add =bluepoint
            if add:
                blue.pop(blue.index(add))
                ans +=1
                        
print(ans)

Submission status: Wrong Answer

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

ans=0
for i in range(2*n):
    now = 2*n -1 -i
    for redpoint in red:
        if redpoint[0] == now:
            value=300
            add=[]
            for bid,bluepoint in enumerate(blue):
                if (bluepoint[0]>redpoint[0])and(bluepoint[1]>redpoint[1]):
                    if value>bluepoint[1]:
                        value =bluepoint[1]
                        add =bluepoint
                        blue.pop(bid)
                        ans +=1
            if redpoint[0]==redpoint[1] and add:
                break
        if redpoint[1] == now:
            value=300
            add=[]
            for bid,bluepoint in enumerate(blue):
                if (bluepoint[0]>redpoint[0])and(bluepoint[1]>redpoint[1]):
                    if value>bluepoint[0]:
                        value =bluepoint[0]
                        add =bluepoint
                        blue.pop(bid)
                        ans +=1
                        
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
lired = [list(map(int,input().split())) for _ in range(n)]
liblue = [list(map(int,input().split())) for _ in range(n)]
lired = sorted(lired,key = lambda x:min(x[0],x[1]))
lired.reverse()
liblue = sorted(liblue,key = lambda x:min(x[0],x[1]))
liblue.reverse()
place = -1
cnt = 0
#print(lired)
#print(liblue)
for i in range(n):
  if place == n-1:
    break
  for j in range(place+1,n):
    if lired[i][0] < liblue[j][0] and lired[i][1] < liblue[j][1]:
      cnt += 1
      place = j
      #print("{} {}".format(i,j))
      break
print(cnt)

Submission status: Wrong Answer

Solution code:
# ABC091C - 2D Plane 2N Points (ARC092C)
import sys
input = sys.stdin.readline

def main():
    N = int(input())
    A = sorted([tuple(map(int, input().split())) for _ in range(N)], key=sum, reverse=1)
    B = sorted([tuple(map(int, input().split())) for _ in range(N)], key=sum, reverse=1)
    ans, memo = 0, set()
    for a in A:
        for i, b in enumerate(B):
            if i not in memo and a[0] < b[0] and a[1] < b[1]:
                ans += 1
                memo |= {i}
                break
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())

red = [0] * N
blue = [0] * N

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

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

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

ans = 0

for bp in blue:
    rem = None
    if len(red) > 0:
        for rp in red:
            if bp[0] > rp[0] and bp[1] > rp[1]:
                # gen pair
                ans += 1
                rem = rp
                break

    if rem is not None:
        red.remove(rem)

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
red = []
blue = []

for i in range(n):
    l = list(map(int,input().split()))
    red.append(l)
for i in range(n):
    l = list(map(int,input().split()))
    blue.append(l)

done = []
for i in range(n):
    bag = []
    cnt = 0
    x = blue[i][0]
    y = blue[i][1]
    for j in range(n):
        if (x > red[j][0]) and (y > red[j][1]):
            if red[j] not in done:
                bag.append(red[j])
                cnt += 1
    bag.sort(key = lambda x:x[1])
    if cnt != 0:
        done.append(bag[cnt-1])
print(len(done))

Submission status: Wrong Answer

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

def count(red, blue):
    used_red = []
    used_blue = []
    for i in red:
        if i in used_red:
            continue
        for j in blue:
            if j in used_blue:
                continue
            if i[0] < j[0] and i[1] < j[1]:
                used_red.append(i)
                used_blue.append(j)
                break
    return len(used_red)

ans = count(red_li, blue_li)
red_li.sort(reverse = True,key = lambda x : (x[1], x[0]))
blue_li.sort( key = lambda x : (x[1], x[0]))
print(max(ans, count(red_li, blue_li)))

Submission status: Wrong Answer

Solution code:
n=int(input())
a=sorted([list(map(int,input().split())) for _ in [0]*n],reverse=True)
b=sorted([list(map(int,input().split())) for _ in [0]*n],reverse=True)
c=0
i=j=0
while j<n:
    i=0
    while i<len(a):
        if a[i][0]<b[j][0] and a[i][1]<b[j][1]:
            c+=1
            del a[i]
            break
        i+=1
    j+=1
print(c)

Submission status: Wrong Answer

Solution code:
import sys
def main():
    input=sys.stdin.readline
    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(reverse=True)
    B.sort(reverse=True)
    ans=0
    cnt=0
    for i in range(N):
        c,d=B[i][0],B[i][1]
        for j in range(N-cnt):
            a,b=R[j][0],R[j][1]
            if c>a and d>b:
                ans+=1
                R=R[:j]+R[j+1:]
                cnt+=1
                break
            else:
                pass
    print(ans)
if __name__=="__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
def main():
    input=sys.stdin.readline
    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(reverse=True)
    B.sort(reverse=True)
    ans=0
    for i in range(N):
        c,d=B[i][0],B[i][1]
        for j in range(N-i):
            a,b=R[j][0],R[j][1]
            if c>a and d>b:
                ans+=1
                R=R[:j]+R[j+1:]
                break
            else:
                pass
    print(ans)
if __name__=="__main__":
    main()

Submission status: Wrong Answer

Solution code:
from functools import reduce
import math
from operator import itemgetter

def main():
    # 文字列の2進数を数値にする
    # '101' → '5'
    # 文字列の頭に'0b'をつけてint()にわたす
    # binary = int('0b'+'101',0)

    # 2進数で立っているbitを数える
    # 101(0x5) → 2
    # cnt_bit = bin(5).count('1')
    
    # N! を求める
    # f = math.factorial(N)

    # N の逆元
    # N_inv = pow(N,MOD-2,MOD)

    # nCr
    # Nの階乗 * rの階乗の逆元 * n-rの階乗の逆元
    
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    INF = float("inf")

    # 大きな素数
    MOD = 10**9+7
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    
    N = int(input())
    ab = []
    cd = []
    for i in range(N):
        s1, s2 = (int(_) for _ in input().split())
        ab.append((s1,s2))
    for i in range(N):
        s1, s2 = (int(_) for _ in input().split())
        cd.append((s1,s2))
    cnt = 0
    ab = sorted(ab, key = itemgetter(0))
    ab = ab[::-1]
    cd = sorted(cd, key = itemgetter(0))
    cd = cd[::-1]
    is_cd_used = [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] and is_cd_used[j]==0:
                cnt +=1
                is_cd_used[j] = 1
                break
    print(cnt)
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N=int(input())
AB=[list(map(int,input().split())) for _ in range(N)]
CD=[list(map(int,input().split())) for _ in range(N)]
tab=[[0]*N for _ in range(N)]
for i, (a, b) in enumerate(AB):
    for j,(c, d) in enumerate(CD):
        if a<c and b<d:
            tab[j][i]=1
ans=0
for i in range(N):
    pairs = sorted([(sum(tab[j]), j) for j in range(N) if tab[j][i]>0])
    if len(pairs)>0:
        _,j=pairs[0]
        tab[j]=[0]*N
        ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
r=[list(map(int, input().split())) for i in range(n)]
b=[list(map(int, input().split())) for i in range(n)]
v=[]
r.sort()
b.sort()
count=0
 
for i in range(n):
    for j in range(len(r)):
        if b[i][0]<=r[j][0] or b[i][1]<=r[j][1]:
            break
        else:
            v.append(r[j])    
    if v!=[]:
        v.sort(key=lambda x:x[1])
        v.reverse()
        r.remove(v[0])
        
            
        v=[]
        count+=1
print(count)

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)]
ans = 0
red = sorted(red, key = lambda x:x[0] * -1)
blue = sorted(blue)
for b in blue:
	for r in red:
		if b[0] > r[0] and b[1] > r[1]:
			ans += 1
			red.remove(r)
			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) ]
R=sorted(R,reverse=True)
B.sort()
ans=0
for b in B:
    for r in R:
        if b[1]>r[1] and b[0]>r[0]:
            ans+=1
            R.remove(r)
            break
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import math

# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev
 
def main():
    N = int(input())
    aka = []
    ao = []
    for i in range(N):
        a,b = map(int, input().split())
        aka.append((a,b,False))
            
    for i in range(N):
        c,d = map(int, input().split())
        ao.append((c,d))
            
    ao.sort()
    ans = 0
    for i, val in enumerate(ao):
        c, d = val
        y_max = -1
        index = -1
        for j , vol in enumerate(aka):
            a, b, partner = vol
            if a < c and partner == False:
                if y_max == -1 or y_max < b:
                    y_max = b
                    index = j
                    
        if y_max != -1:
            ans += 1
            a, b, partner = aka[index]
            partner = True
            aka[index] = (a, b, partner)
            y_max = -1
            index = -1
            
    print(ans)
    
	
if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import math

# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev
 
def main():
    N = int(input())
    aka = []
    ao = []
    for i in range(N):
        a,b = map(int, input().split())
        aka.append((a,b,False))
            
    for i in range(N):
        c,d = map(int, input().split())
        ao.append((c,d))
            
    ao.sort()
    ans = 0
    for i, val in enumerate(ao):
        c, d = val
        y_max = -1
        for j , vol in enumerate(aka):
            a, b, partner = vol
            if a < c and partner == False:
                if y_max == -1 or y_max < b:
                    y_max = j
        if y_max != -1:
            ans += 1
            a, b, partner = aka[y_max]
            partner = True
            aka[y_max] = (a, b, partner)
            y_max = -1
            
    print(ans)
    
	
if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
n = int(input())
info = [list(map(int, input().split())) for i in range(2*n)]

for i in range(n):
    info[i].append("r")
for i in range(n, 2*n):
    info[i].append("b")
info = sorted(info)
a = []
for i in range(2*n):
    a.append(info[i][1:3])

used = [False] * (2*n)
ans = 0
for i in range(2*n):
    if used[i]:
        continue
    used[i] = True
    if a[i][1] == "b":
        continue
    ind = -1
    num = 10**5
    for j in range(i+1, 2*n):
        if not used[j] and a[i][0] < a[j][0] and a[j][1] == "b":
            if a[j][0] < num:
                ind = j
                num = a[j][0]
    if ind != -1:
        used[ind] = True
        ans += 1
print(ans)

Submission status: Wrong Answer

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

N = int(input())

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

tab = [[i, []] for i in range(N)]
for i, (ai, bi) in enumerate(ab):
    for j, (cj, dj) in enumerate(cd):
        if ai < cj and bi < dj:
            tab[i][1].append(j)
        
tab.sort(key=lambda x: len(x[1]))

idx = [None] * N
for i in range(N):
    idx[tab[i][0]] = i
    
for i in range(N):
    tab[i][1].sort(key=lambda x: idx[x])

# print("#", tab)

ans = 0
b_used = [False] * N
for i in range(N):
    for j in tab[i][1]:
        if b_used[idx[j]]:
            continue
        else:
            ans += 1
            b_used[idx[j]] = True
            break
            
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
R = []
B = []
ans = 0
for i in range(N):
  a,b = map(int,input().split())
  R.append((a,b))
for i in range(N):
  c,d = map(int,input().split())
  B.append((c,d))
R.sort(key=lambda x:x[0])
B.sort(key=lambda x:x[0])
H = []
l = 0
for i in range(N):
  for j in range(l,N):
    if R[j][0] > B[i][0]:
      l = j
      break
    H.append(R[j])
  H.sort(key=lambda x:x[1], reverse=True)
  print(H)
  for k in range(len(H)):
    if H[k][1] < B[i][1]:
      H.pop(k)
      ans += 1
      break
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict


def is_ok(r, b):
    return r[0] < b[0] and r[1] < b[1]


N = int(input())
R = [tuple(map(int, input().split())) for _ in range(N)]
B = [tuple(map(int, input().split())) for _ in range(N)]
S = [set() for _ in range(N)]
for i, r in enumerate(R):
    for j, b in enumerate(B):
        if is_ok(r, b):
            S[i].add(j)
D = {i: len(S[i]) for i in range(N)}
E = defaultdict(lambda: set())
biggest = -float("inf")
smallest = float("inf")
for k, v in D.items():
    biggest = max(biggest, v)
    smallest = min(smallest, v)
    E[v].add(k)
ans = 0
for v in range(smallest, 1 + biggest):
    for i in E[v]:
        if S[i]:
            ans += 1
            j = S[i].pop()
            for s in S:
                if j in s:
                    s.remove(j)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
red = []
for i in range(0, N):
	red.append(list(map(int, input().split())))
blue = []
for i in range(0, N):
	blue.append(list(map(int, input().split())))
blue.sort(key = lambda v: v[1])
blue.sort(key = lambda v: v[0])
cnt = 0
for i in range(0, N):
	redlist = []
	for j in range(0, len(red)):
		if red[j][0] < blue[i][0] and red[j][1] < blue[i][0]:
			redlist.append([j, red[j]])
	if redlist != []:
		redlist.sort(lambda v: v[1], reverse = True)
		cnt += 1
		red.pop(redlist[0][0])
print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
red = []
for i in range(0, N):
	red.append(list(map(int, input().split())))
blue = []
for i in range(0, N):
	blue.append(list(map(int, input().split())))
blue.sort(key = lambda v: v[0])
cnt = 0
for i in range(0, N):
	redlist = []
	for j in range(0, len(red)):
		if red[j][0] < blue[i][0] and red[j][1] < blue[i][0]:
			redlist.append([j, red[j]])
	if redlist != []:
		redlist.sort(lambda v: v[1], reverse = True)
		cnt += 1
		red.pop(redlist[0][0])
print(cnt)

Submission status: Wrong Answer

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

N = int(input())

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

ans_x = 0
used = [False] * N
for ai, bi in sorted(ab, key=lambda x: x[0]):
    for j, (cj, dj) in enumerate(sorted(cd, key=lambda x: x[0])):
        if used[j]: continue
        if ai >= cj or bi >= dj: continue
        #
        # print("# x", (ai, bi), (cj, dj))
        used[j] = True
        ans_x += 1
        break

ans_y = 0
used = [False] * N
for ai, bi in sorted(ab, key=lambda x: x[1]):
    for j, (cj, dj) in enumerate(sorted(cd, key=lambda x: x[1])):
        if used[j]: continue
        if ai >= cj or bi >= dj: continue
        #
        # print("# y", (ai, bi), (cj, dj))
        used[j] = True
        ans_y += 1
        break
        
print(max(ans_x, ans_y))

Submission status: Wrong Answer

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

N = int(input())
A = [[int(v) for v in input().split()] for _ in range(N)]
B = [[int(v) for v in input().split()] for _ in range(N)]

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

ans = 0
for i in range(N):
    a = A[i]
    
    for j in range(N):
        b = B[j]

        if a[0] < b[0] and a[1] < b[1]:
            ans += 1
            b[0] = 0
            b[1] = 0
            break

print(ans)

Submission status: Wrong Answer

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

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

count = 0
for red_p in sorted_red:
    for blue_p in sorted_blue:
        if red_p < blue_p:
            count += 1
            del sorted_blue[: 1 + sorted_blue.index(blue_p)]
            break

print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())

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

reds.sort()
blues.sort()

ans = 0
for blue in blues:
    c, d = blue

    reds_under_x = [red for red in reds if red[0] < c]
    reds_under_x.sort(key=lambda x:x[1])

    if reds_under_x:
        target = reds_under_x.pop()
        reds.remove(target)
        ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(N, inputs):
    ball_str = list(map(lambda i: string_to_int(i), inputs))
    balls = list(map(lambda b: [b[0], b[1], -1], ball_str))

    red = balls[:N]
    blue = balls[N:]

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

    count = 0
    for i, r in enumerate(red):
        for j, b in enumerate(blue):
            if r[0] < b[0] and r[1] < b[1] and b[2] == -1:
                count += 1
                r[2] = j
                b[2] = i
                break
    return count


def string_to_int(string):
    return list(map(lambda x: int(x), string.split()))


if __name__ == "__main__":
    [N] = string_to_int(input())
    ret = solve(N, inputs(2*N))
    print(ret)

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(N, inputs):
    ball_str = list(map(lambda i: string_to_int(i), inputs))
    balls = list(map(lambda b: [b[0], b[1], -1], ball_str))

    red = balls[:N]
    blue = balls[N:]

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

    count = 0
    for i, r in enumerate(red):
        for j, b in enumerate(blue):
            if r[0] < b[0] and r[1] < b[1] and b[2] == -1:
                count += 1
                r[2] = j
                b[2] = i
                break
    return count


def string_to_int(string):
    return list(map(lambda x: int(x), string.split()))


if __name__ == "__main__":
    [N] = string_to_int(input())
    ret = solve(N, inputs(2*N))
    print(ret)

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
    N = int(input())
    ab_list = [list(map(int, input().split())) for i in range(N)]
    cd_list = [list(map(int, input().split())) for i in range(N)]

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

    print(ab_list)
    print(cd_list)

    answer = 0
    for b in cd_list:
        for r in ab_list:
            if b[0]>r[0] and b[1]>r[1]:
                answer += 1
                ab_list.remove(r)
                print(b)
                print(r)
                print("------")
                break
    print(answer)

Submission status: Wrong Answer

Solution code:
n=int(input())
ab=[list(map(int,input().split())) for _ in range(n)]
cd=[list(map(int,input().split())) for _ in range(n)]
ab.sort(key=lambda x:x[1], reverse=True)
ab.sort()
cd.sort(key=lambda x:x[1])
cd.sort()
ans=0
for i in range(n):
    for a in ab:
        if a[0]<cd[i][0] and a[1]<cd[i][1]:
            ans+=1
            ab.remove(a)
            break
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
ab=[list(map(int,input().split())) for _ in range(n)]
cd=[list(map(int,input().split())) for _ in range(n)]
ab.sort(key=lambda x:x[1])
ab.sort()
cd.sort(key=lambda x:x[1])
cd.sort()
cou=0
ans=0
for i in range(n):
    while cou<n:
        if ab[i][0]<cd[cou][0] and ab[i][1]<cd[cou][1]:
            ans+=1
            cou+=1
            break
        cou+=1
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())

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

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


a2=sorted(a, key=lambda x: x[0])
b2=sorted(b, key=lambda x: x[0])

ans=0
for i in range(n):
    for j in range(n):
        if b2[i][0]>a2[n-1-j][0] and b2[i][1]>a2[n-1-j][1]:
            ans+=1
            a2[n-1-j][0]=3*n
            break

print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())

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

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


a2=sorted(a, key=lambda x: x[0])
b2=sorted(b, key=lambda x: x[0])

ans=0
for i in range(n):
    for j in range(n):
        if b2[n-1-i][0]>a2[n-1-j][0] and b2[n-1-i][1]>a2[n-1-j][1]:
            ans+=1
            a2[n-1-j][0]=3*n
            break

print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())

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

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


a2=sorted(a, key=lambda x: x[0])
b2=sorted(b, key=lambda x: x[0])

ans=0
for i in range(n):
    for j in range(n):
        if b2[n-1-i][0]>a2[n-1-j][0] and b2[n-1-i][1]>a2[n-1-j][1]:
            ans+=1
            a2[n-1-j][0]=2*n

print(ans)

Submission status: Wrong Answer

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

ab, cd = sorted(AB)[::-1], sorted(CD)[::-1]

pair_count = 0
for c, d in cd:
	for i, (a, b) in enumerate(ab):
		if a < c:
			highest_p = (i, (a, b))
			for j, (a, b) in enumerate(ab[i + 1:]):
				if highest_p[1][1] < b:
					highest_p = (j, (a, b))
			pair_count += 1
			del ab[highest_p[0]]
			break
print(pair_count)

Submission status: Wrong Answer

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

ab, cd = sorted(AB)[::-1], sorted(CD)[::-1]

pair_count = 0
for a, b in ab:
	for i, (c, d) in enumerate(cd):
		if a < c:
			highest_p = (i, (c, d))
			for j, (c, d) in enumerate(cd[i + 1:]):
				if highest_p[1][1] < d:
					highest_p = (j, (c, d))
			pair_count += 1
			del cd[highest_p[0]]
			break
print(pair_count)

Submission status: Wrong Answer

Solution code:
n = int(input())
red = []
blue = []
for _ in range(n):
    a, b = map(int, input().split())
    red.append([a, b])
for _ in range(n):
    c, d = map(int, input().split())
    blue.append([c, d])
blue.sort()
red.sort(key=lambda x: x[1])
ans = 0
for b in blue:
    for i, r in enumerate(red):
        if (r[0] < b[0]) & (r[1] < b[1]):
            ans += 1
            red.pop(i)
            break
print(ans)

Submission status: Wrong Answer

Solution code:
import copy
n = int(input())
red = []
blue = []
for _ in range(n):
    a, b = map(int, input().split())
    red.append([a, b])
for _ in range(n):
    c, d = map(int, input().split())
    blue.append([c, d])

red_list = copy.copy(red)
blue_list = copy.copy(blue)
    
red_list.sort()
blue_list.sort()
count = 0
for i in range(n):
    a, b = red_list.pop(0)
    for j in range(len(blue_list)):
        if (a < blue_list[j][0]) & (b < blue_list[j][1]):
            count += 1
            blue_list.pop(j)
            break

red_list = copy.copy(red)
blue_list = copy.copy(blue)
    
red_list.sort(key=lambda x: x[1])
blue_list.sort(key=lambda x: x[1])
count1 = 0
for i in range(n):
    a, b = red_list.pop(0)
    for j in range(len(blue_list)):
        if (a < blue_list[j][0]) & (b < blue_list[j][1]):
            count1 += 1
            blue_list.pop(j)
            break            

ans = max(count, count1)        
print(ans)