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())
a = []
b = []
for i in range(n):
    a.append(list(map(int,input().split())))
for i in range(n):
    b.append(list(map(int,input().split())))
a.sort()
b.sort()
queue =[]
count = 0
for i in range(n):
    for j in range(n):
        if (b[i][0] > a[j][0]) and (b[i][1] > a[j][1]):
            if not a[j] in queue:
                count += 1
                queue.append(a[j])
                break
print(count)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

# 青い点を探して処理する関数
def search_bluedot(start_x, start_y):
	# 更新する値をグローバル宣言
	global ans
	global field
	for i in range(start_x, dot_count*2):
		for j in range(start_y, dot_count*2):
			# 青い点を見つけたら、答えを+1して青い点を消す
			if field[i][j] == 2:
				ans += 1
				field[i][j] = 0
				return

dot_count = int(input())
# 点を置くフィールドを作成
field = [[0 for i in range(dot_count*2)] for j in range(dot_count*2)]
# 赤い点の配置
for i in range(dot_count):
	x, y = map(int, input().split())
	field[y][x] = 1
# 青い点の配置
for i in range(dot_count):
	x, y = map(int, input().split())
	field[y][x] = 2

ans = 0
for i in range(dot_count*2):
	for j in range(dot_count*2):
		# 赤い点を見つけたら、そこより外側で青い点を探す
		if field[i][j] == 1:
			search_bluedot(i+1, j+1)

print(ans)

Submission status: Wrong Answer

Solution code:
n = input()
x = sorted([raw_input().split() for i in range(n)])[::-1]
y = sorted([raw_input().split() for i in range(n)])[::-1]
used = [False] * n
for i in range(n):
    a, b = x[i]
    for j in range(n):
        c, d = y[j]
        if not used[j] and (a < c) and (b < d):
            used[j] = True
            break
print sum(used)

Submission status: Wrong Answer

Solution code:
n=int(input())
red=[list(map(int,input().split()))for i in range(n)]
blue=[list(map(int,input().split()))for i in range(n)]
red.sort()
blue.sort()
ans=0
for i in range(n):
    redx,redy=red[i][0],red[i][1]
    for j in range(len(blue)):
        bluex,bluey=blue[j][0],blue[j][1]
        if redx<bluex and redy<bluey:
            ans+=1
            blue.pop(j)
            break
print(ans)

Submission status: Wrong Answer

Solution code:
def less_than(a, b):
    return a[0] < b[0] and a[1] < b[1]

n = int(input())
a = []
b = []
for _ in range(n):
    ax, ay = input().split()
    a.append((int(ax), int(ay)))
for _ in range(n):
    bx, by = input().split()
    b.append((int(bx), int(by)))
a = sorted(a, key=lambda x:x[0], reverse=False)
b = sorted(b, key=lambda x:x[1], reverse=True)
ans = 0
for i in range(n):
    if less_than(a[i], b[i]):
        ans += 1
print(ans)

Submission status: Wrong Answer

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

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

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

#print('red:', red)
#print('blue:', blue)

pairs = []

for i in range(len(red)): #red[i]とペアになりうるものを探す
    if_break = 'false'    
#     if len(pairs) > 0:
#         print(pairs)
#     else:
#         print('not pairs')
        
    for j in range(i,len(blue)):
#         print(i,j)
#         print(red[i],blue[j])
        
        if if_break =='true':
            break
            
        if (red[i][0] < blue[i][0]) & (red[j][1] < blue[j][1]):
            pairs.append([red[i], blue[j]])
            if_break = 'true'
            break

    if if_break == 'true':
        continue
        
# print(pairs)
print(len(pairs))

Submission status: Wrong Answer

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

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

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

#print('red:', red)
#print('blue:', blue)

pairs = []

for i in range(len(red)): #red[i]とペアになりうるものを探す
    if_break = 'false'    
#     if len(pairs) > 0:
#         print(pairs)
#     else:
#         print('not pairs')
        
    for j in range(i,len(blue)):
#         print(i,j)
#         print(red[i],blue[j])
        
#        if if_break =='true':
#            break
            
        if (red[i][0] < blue[i][0]) & (red[j][1] < blue[j][1]):
            pairs.append([red[i], blue[j]])
            if_break = 'true'
            break

    if if_break == 'true':
        continue
        
# print(pairs)
print(len(pairs))

Submission status: Wrong Answer

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

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

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

#print('red:', red)
#print('blue:', blue)

pairs = []
for i in range(len(red)): #red[i]とペアになりうるものを探す
    for j in range(len(blue)):
        if blue[j][0] >= red[i][0] and blue[j][1] >= red[i][1]:
            pairs.append([red[i],blue[i]])
            break
        else:
            continue
#print(pairs)
    continue

print(len(pairs))

Submission status: Wrong Answer

Solution code:
N=int(input())
AB=[]
for i in range(N):
    AB.append(list(map(int,input().split())))
CD=[]
for i in range(N):
    CD.append(list(map(int,input().split())))
AB=sorted(AB,key=lambda x:x[0]+x[1]*300)
CD=sorted(CD,key=lambda x:x[0]+x[1]*300)
ct=0
for ab in AB[::-1]:
    for i in range(len(CD))[::-1]:
        cd=CD[i]
        if ab[0]<cd[0] and ab[1]<cd[1]:
            ct+=1
            CD.pop(i)
            break
print(ct)

Submission status: Wrong Answer

Solution code:
n = int(input())
ab = [[int(i) for i in input().split()] for _ in range(n)]
ab = sorted(ab, key=lambda x:x[0])
cd = sorted([[int(i) for i in input().split()] for _ in range(n)])
count = 0
out = []
output = []
for c in cd:
    flag = 0
    for a in ab:
        if c not in output and a[0]<c[0] and a[1]<c[1]:
            out.append(a)
            flag = 1
    if flag == 1:
        output.append(max(out, key=lambda x:x[1]))
        out = []
        count += 1

print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
ab = [[int(i) for i in input().split()] for _ in range(n)]
ab = sorted(ab, key=lambda x:x[0])
cd = sorted([[int(i) for i in input().split()] for _ in range(n)])
count = 0
out = []
output = []
for a in ab:
    flag = 0
    for c in cd:
        if c not in output and a[0]<c[0] and a[1]<c[1]:
            out.append(c)
            flag = 1
    if flag == 1:
        output.append(min(out, key=lambda x:x[1]))
        out = []
        count += 1

print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
ab = sorted([[int(i) for i in input().split()] for _ in range(n)])
ab = sorted(ab)
cd = [[int(i) for i in input().split()] for _ in range(n)]
count = 0
out = []
output = []
for a in ab:
    flag = 0
    for c in cd:
        if c not in output and a[0]<c[0] and a[1]<c[1]:
            out.append(c)
            flag = 1
    if flag == 1:
        output.append(max(out, key=lambda x:x[1]))
        out = []
        count += 1

print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
ab = sorted([[int(i) for i in input().split()] for _ in range(n)])
ab = sorted(ab)
cd = [[int(i) for i in input().split()] for _ in range(n)]
count = 0
out = []
output = []
for a in ab:
    for c in cd:
        if c not in output and a[0]<c[0] and a[1]<c[1]:
            out.append(c)
    else:
        continue
    output.append(max(out, key=lambda x:x[1]))
    count += 1

print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
ab = [[int(i) for i in input().split()] for _ in range(n)]
ab = sorted(ab)
cd = [[int(i) for i in input().split()] for _ in range(n)]
cd = sorted(cd)
count = 0
out = []
for a in ab:
    for c in cd:
        if c not in out and a[0]<c[0] and a[1]<c[1]:
            out.append(c)
            count += 1
print(count)

Submission status: Wrong Answer

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

count = 0    
for i in range(n):
    p = max(red_x)
    s = min(blue_y)
    q = 0
    r = 0
    jjj = 0
    kkk = 0
    for j in range(len(red)):
        if red[j][0] == p:
            q = red[j][1]
            jjj = j
    for k in range(len(blue)):
        if blue[k][1] == s:
            r = blue[k][0]
            kkk = k
            
    if p < r and q < s:
        count = count + 1 
        red_x.remove(p)
        blue_y.remove(s)



    else:
        None
        
print(count)

Submission status: Wrong Answer

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

count = 0    
for i in range(n):
    p = max(red_x)
    s = min(blue_y)
    q = 0
    r = 0
    for j in range(n):
        if red[j][0] == p:
            q = red[j][1]
            red[j][0] = -1
            red[j][1] = -1
    for k in range(n):
        if blue[k][1] == s:
            r = blue[k][0]
            blue[k][0] = -1
            blue[k][1] = -1
            
    if p < r and q < s:
        count = count + 1 
        red_x.remove(p)
        blue_y.remove(s)


    else:
        None
        
print(count)

Submission status: Wrong Answer

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

count = 0    
for i in range(n):
    p = max(red_x)
    red_x.remove(p)
    s = min(blue_y)
    blue_y.remove(s)
    q = 0
    r = 0
    for j in range(n):
        if red[j][0] == p:
            q = red[j][1]
            red[j][0] = -1
            red[j][1] = -1
    for k in range(n):
        if blue[k][1] == s:
            r = blue[k][0]
            blue[k][0] = -1
            blue[k][1] = -1
            
    if p < r and q < s:
        count = count + 1 
    else:
        None
        
print(count)

Submission status: Wrong Answer

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

count = 0    
for i in range(n):
    p = max(red_x)
    red_x.remove(p)
    s = min(blue_y)
    blue_y.remove(s)
    q = 0
    r = 0
    for j in range(n):
        if red[j][0] == p:
            q = red[j][1]
            red[j][0] = -1
            red[j][1] = -1
    for k in range(n):
        if blue[k][1] == s:
            r = blue[k][0]
            blue[k][0] = -1
            blue[k][1] = -1
            
    if p < r and q < s:
        count = count + 1
    else:
        None
            
    
            
print(count)

Submission status: Wrong Answer

Solution code:
my_input = input

def less_than(a, b):
    return a[0] < b[0] and a[1] < b[1]

n = int(my_input())
a = []
b = []
for _ in range(n):
    ax, ay = my_input().split()
    a.append((int(ax), int(ay)))
for _ in range(n):
    bx, by = my_input().split()
    b.append((int(bx), int(by)))
a = sorted(a, key=lambda x:x[1], reverse=True)
b = sorted(b, key=lambda x:x[0], reverse=False)
ans = 0
ii = set()
for j in range(n):
    for i in range(n):
        if i in ii:
            continue
        if less_than(a[i], b[j]):
            ans += 1
            ii.add(j)
            break
print(ans)

Submission status: Wrong Answer

Solution code:
def less_than(a, b):
    return a[0] < b[0] and a[1] < b[1]

n = int(input())
a = []
b = []
for _ in range(n):
    ax, ay = input().split()
    a.append((int(ax), int(ay)))
for _ in range(n):
    bx, by = input().split()
    b.append((int(bx), int(by)))
a = sorted(a, key=lambda x:(x[0],x[1]), reverse=False)
b = sorted(b, key=lambda x:(x[0],x[1]), reverse=True)
ans = 0
for i in range(n):
    if less_than(a[i], b[i]):
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())

red_x = []
red_y = []
blue_x = []
blue_y = []
for ls in [[red_x,red_y], [blue_x,blue_y]]:
    for i in range(n):
        x, y = map(int, input().split())
        ls[0].append(x)
        ls[1].append(y)
        
red_x = np.array(red_x)
red_y = np.array(red_y)
blue_x = np.array(blue_x)
blue_y = np.array(blue_y)


def abc091c(red_x, red_y, blue_x, blue_y, count):
    if len(blue_x) > 0:
        blue_min_index = np.where(blue_x == min(blue_x))[0][0] #blue_xの最小値のindexを求める
        x_threshold = blue_x[blue_min_index] #x軸のペア生成可能しきい値
        y_threshold = blue_y[blue_min_index] #y軸のペア生成可能しきい値

        enable_pair_indexes = []
        for i, (r_x, r_y) in enumerate(zip(red_x, red_y)):
            if r_x < x_threshold and r_y < y_threshold:
                enable_pair_indexes.append(i)

        if len(enable_pair_indexes) > 0:
            enable_pair_index = np.where(red_y == max(red_y[enable_pair_indexes]))[0][0]
            #赤い点削除
            red_x = np.delete(red_x, enable_pair_index)
            red_y = np.delete(red_y, enable_pair_index)
            #カウント増加
            count += 1
            
        #青い点削除
        blue_x = np.delete(blue_x, blue_min_index)
        blue_y = np.delete(blue_y, blue_min_index)
        print(red_x, red_y, blue_x, blue_y)

        abc091c(red_x, red_y, blue_x, blue_y, count)
    else:
        print(count)

count = 0
abc091c(red_x, red_y, blue_x, blue_y, count)

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())

red_x = []
red_y = []
blue_x = []
blue_y = []
for ls in [[red_x,red_y], [blue_x,blue_y]]:
    for i in range(n):
        x, y = map(int, input().split())
        ls[0].append(x)
        ls[1].append(y)
        
red_x = np.array(red_x)
red_y = np.array(red_y)
blue_x = np.array(blue_x)
blue_y = np.array(blue_y)


def abc091c(red_x, red_y, blue_x, blue_y, count):
    if len(blue_x) > 0:
        blue_min_index = np.where(blue_x == min(blue_x))[0][0] #blue_xの最小値のindexを求める
        x_threshold = blue_x[blue_min_index] #x軸のペア生成可能しきい値
        y_threshold = blue_y[blue_min_index] #y軸のペア生成可能しきい値

        enable_pair_indexes = []
        for i, (r_x, r_y) in enumerate(zip(red_x, red_y)):
            if r_x < x_threshold and r_y < y_threshold:
                enable_pair_indexes.append(i)

        if len(enable_pair_indexes) > 0:
            enable_pair_index = np.where(red_y == min(red_y[enable_pair_indexes]))[0][0]
            #赤い点削除
            red_x = np.delete(red_x, enable_pair_index)
            red_y = np.delete(red_y, enable_pair_index)
            #カウント増加
            count += 1
            
        #青い点削除
        blue_x = np.delete(blue_x, blue_min_index)
        blue_y = np.delete(blue_y, blue_min_index)

        abc091c(red_x, red_y, blue_x, blue_y, count)
    else:
        print(count)

count = 0
abc091c(red_x, red_y, blue_x, blue_y, count)

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())

red_x = []
red_y = []
blue_x = []
blue_y = []
for ls in [[red_x,red_y], [blue_x,blue_y]]:
    for i in range(n):
        x, y = map(int, input().split())
        ls[0].append(x)
        ls[1].append(y)
        
red_x = np.array(red_x)
red_y = np.array(red_y)
blue_x = np.array(blue_x)
blue_y = np.array(blue_y)


def abc091c(red_x, red_y, blue_x, blue_y, count):
    if len(blue_x) != 0:
        blue_min_index = np.where(blue_x == min(blue_x))[0][0] #blue_xの最小値のindexを求める
        x_threshold = blue_x[blue_min_index] #x軸のペア生成可能しきい値
        y_threshold = blue_y[blue_min_index] #y軸のペア生成可能しきい値

        enable_pair_indexes = []
        for i, (r_x, r_y) in enumerate(zip(red_x, red_y)):
            if r_x < x_threshold and r_y < y_threshold:
                enable_pair_indexes.append(i)

        if len(enable_pair_indexes) != 0:
            enable_pair_index = np.where(red_y == min(red_y[enable_pair_indexes]))[0]
            #赤い点削除
            red_x = np.delete(red_x, enable_pair_index)
            red_y = np.delete(red_y, enable_pair_index)
            #カウント増加
            count += 1
            
        #青い点削除
        blue_x = np.delete(blue_x, blue_min_index)
        blue_y = np.delete(blue_y, blue_min_index)

        abc091c(red_x, red_y, blue_x, blue_y, count)
    else:
        print(count)

count = 0
abc091c(red_x, red_y, blue_x, blue_y, count)

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())

red_x = []
red_y = []
blue_x = []
blue_y = []
for ls in [[red_x,red_y], [blue_x,blue_y]]:
    for i in range(n):
        x, y = map(int, input().split())
        ls[0].append(x)
        ls[1].append(y)
        
red_x = np.array(red_x)
red_y = np.array(red_y)
blue_x = np.array(blue_x)
blue_y = np.array(blue_y)


def abc091c(red_x, red_y, blue_x, blue_y, count):
    if len(blue_x) != 0:
        blue_min_index = np.where(blue_x == min(blue_x))[0] #blue_xの最小値のindexを求める
        x_threshold = blue_x[blue_min_index] #x軸のペア生成可能しきい値
        y_threshold = blue_y[blue_min_index] #y軸のペア生成可能しきい値

        enable_pair_indexes = np.where(red_x < x_threshold)[0]
        if len(enable_pair_indexes) != 0:
            enable_pair_index = np.where(red_y == min(red_y[enable_pair_indexes]))[0]
            #赤い点削除
            red_x = np.delete(red_x, enable_pair_index)
            red_y = np.delete(red_y, enable_pair_index)
            #カウント増加
            count += 1
            
        #青い点削除
        blue_x = np.delete(blue_x, blue_min_index)
        blue_y = np.delete(blue_y, blue_min_index)

        abc091c(red_x, red_y, blue_x, blue_y, count)
    else:
        print(count)

count = 0
abc091c(red_x, red_y, blue_x, blue_y, count)

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())

red_x = []
red_y = []
blue_x = []
blue_y = []
for ls in [[red_x,red_y], [blue_x,blue_y]]:
    for i in range(n):
        x, y = map(int, input().split())
        ls[0].append(x)
        ls[1].append(y)
        
red_x = np.array(red_x)
red_y = np.array(red_y)
blue_x = np.array(blue_x)
blue_y = np.array(blue_y)


def abc091c(red_x, red_y, blue_x, blue_y, count):
    if len(blue_x) != 0:
        blue_min_index = np.where(blue_x == min(blue_x)) #blue_xの最小値のindexを求める
        x_threshold = blue_x[blue_min_index] #x軸のペア生成可能しきい値
        y_threshold = blue_y[blue_min_index] #y軸のペア生成可能しきい値

        enable_pair_indexes = np.where(red_x < x_threshold)[0]
        if len(enable_pair_indexes) != 0:
            enable_pair_index = np.where(red_y == min(red_y[enable_pair_indexes]))[0]
            #赤い点削除
            red_x = np.delete(red_x, enable_pair_index)
            red_y = np.delete(red_y, enable_pair_index)
            #カウント増加
            count += 1
            
        #青い点削除
        blue_x = np.delete(blue_x, blue_min_index)
        blue_y = np.delete(blue_y, blue_min_index)

        abc091c(red_x, red_y, blue_x, blue_y, count)
    else:
        print(count)

count = 0
abc091c(red_x, red_y, blue_x, blue_y, count)

Submission status: Wrong Answer

Solution code:
def comp(p, q):
    if p[0]<q[0] and p[1]<q[1]:
        return True
    else:
        return False

n=int(input())
r=sorted([list(map(lambda x:int(x), input().split())) for _ in range(n)])
b=sorted([list(map(lambda x:int(x), input().split())) for _ in range(n)])
rp=n-1
bp=n-1
count=0
for y in reversed(b):
    for x in reversed(r):
        if comp(x, y):
            count+=1
            r.remove(x)
            break
print(count)

Submission status: Wrong Answer

Solution code:
def comp(p, q):
    if p[0]<q[0] and p[1]<q[1]:
        return True
    else:
        return False

n=int(input())
r=sorted([list(map(lambda x:int(x), input().split())) for _ in range(n)])
b=sorted([list(map(lambda x:int(x), input().split())) for _ in range(n)])
rp=n-1
bp=n-1
count=0
for y in reversed(b):
    for x in reversed(r):
        if comp(x, y):
            count+=1
            r.remove(x)
print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
red = []
blue = []
for i in range(n):
    red.append(list(map(int,input().split())))
for i in range(n):
    blue.append(list(map(int,input().split())))
red.sort(reverse = True)
blue.sort()
ans = 0
for i in range(n):
    redx,redy = red[i][0],red[i][1]
    for j in range(len(blue)):
        bluex,bluey = blue[j][0],blue[j][1]
        if redx < bluex and redy < bluey:
            ans += 1
            blue.pop(j)
            break
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
red = []
blue = []
for i in range(n):
    red.append(list(map(int,input().split())))
for i in range(n):
    blue.append(list(map(int,input().split())))
red.sort(reverse = True)
blue.sort(reverse = True)
ans = 0
for i in range(n):
    redx,redy = red[i][0],red[i][1]
    for j in range(len(blue)):
        bluex,bluey = blue[j][0],blue[j][1]
        if redx < bluex and redy < bluey:
            ans += 1
            blue.pop(0)
            break
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
red = []
blue = []
for i in range(n):
    red.append(list(map(int,input().split())))
for i in range(n):
    blue.append(list(map(int,input().split())))
red.sort(reverse = True)
blue.sort(reverse = True)
print(red)
print(blue)
ans = 0
for i in range(n):
    redx,redy = red[i][0],red[i][1]
    for j in range(len(blue)):
        bluex,bluey = blue[j][0],blue[j][1]
        if redx < bluex and redy < bluey:
            ans += 1
            blue.pop(0)
            break
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
red = []
blue = []
for i in range(n):
    red.append(list(map(int,input().split())))
for i in range(n):
    blue.append(list(map(int,input().split())))
red.sort(reverse = True)
blue.sort(reverse = True)
print(red)
print(blue)
ans = 0
for i in range(n):
    redx,redy = red[i][0],red[i][1]
    for j in range(len(blue)):
        print(blue)
        bluex,bluey = blue[j][0],blue[j][1]
        if redx < bluex and redy < bluey:
            ans += 1
            blue.pop(0)
            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] + x[1], reverse=True)
blue.sort(key=lambda x: x[0] + x[1], reverse=True)

cnt = 0
for r in red:
    r_n = r[0] ** 2 + r[1] ** 2
    min_dif = float('inf')
    min_idx = -1
    for idx, b in enumerate(blue):
        b_n = b[0] ** 2 + b[1] ** 2
        if r[0] < b[0] and r[1] < b[1]:
            if b_n - r_n < min_dif:
                min_dif = b_n - r_n
                min_idx = idx
    if min_idx != -1:
        cnt += 1
        blue.pop(min_idx)
print(cnt)

Submission status: Wrong Answer

Solution code:
pair = []
def inpl(): return list(map(int, input().split()))
N = int(input())
a = []
red_y_in_pair = []
for i in range(N):
    temp = inpl()
    temp.append('r')
    a.append(temp)
for i in range(N):
    temp = inpl()
    temp.append('b')
    a.append(temp)

sorted_a = sorted(a)

for n, i in enumerate(sorted_a):
    if i[2] == 'b':
        max_r = -1
        for j in sorted_a[:n]:
            if j[2]=='r' and j[1] not in red_y_in_pair:
                max_r = max(max_r, j[1])
        if max_r != -1:
            red_y_in_pair.append(max_r)
print(len(red_y_in_pair))

Submission status: Wrong Answer

Solution code:
n = int(input())
red_point = []
blue_point = []

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

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

red_point.sort(key=lambda x:x[0])
blue_point.sort(key=lambda x:x[0])

counter = 0

for i in range(n):
    for j in range(n):
        if red_point[i][0] < blue_point[i][0] and red_point[i][1] < blue_point[j][0]:
            counter += 1
            break

print(counter)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter
N = int(input())
r = [[int(i) for i in input().split()] for i in range(N)]
b = [[int(i) for i in input().split()] for i in range(N)]
sr = sorted(r, key=itemgetter(0))
sr = sorted(sr, key=itemgetter(1), reverse=True)
sb = sorted(b, key=itemgetter(0))
sb = sorted(sb, key=itemgetter(1), reverse=True)
r.sort(key=lambda x:(x[0],x[1]))
b.sort(key=lambda x:(x[0],x[1]))
ans = [0 for i in range(2)] 
for i in range(N):
    if r[ans[0]][0]<b[i][0] and r[ans[0]][1]<b[i][1]:
        ans[0] += 1
for i in range(N):
    if sr[ans[1]][0]<sb[i][0] and sr[ans[1]][1]<sb[i][1]:
        ans[1] += 1

print(max(ans))

Submission status: Wrong Answer

Solution code:
N = int(input())
ab = [[0,0] for _ in range(N)]
cd = [[0,0] for _ in range(N)]
for i in range(N):
    ab[i] = list(map(int, input().split()))
for i in range(N):
    cd[i] = list(map(int, input().split()))
ab.sort(key = lambda x:x[0])
cd.sort(key = lambda x:x[0])
cnt = 0

for i in ab:
    tmp = [200,200]
    for j in cd:
        if i[0] < j[0] and i[1] < j[1]:
            if tmp[0] - i[0] >= j[0] - i[0] or tmp[1] - i[1] >= j[1] - i[1]:
                tmp = j
    if not(tmp == [200,200]) :
        cd.remove(tmp)
        cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
ab = [[0,0] for _ in range(N)]
cd = [[0,0] for _ in range(N)]
for i in range(N):
    ab[i] = list(map(int, input().split()))
for i in range(N):
    cd[i] = list(map(int, input().split()))
ab.sort(key = lambda x:x[0])
cd.sort(key = lambda x:x[0])
tmp1 = ab[:]
tmp2 = cd[:]
cnt1 = 0
cnt2 = 0
for i in ab:
    for j in cd:
        if i[0] < j[0] and i[1] < j[1]:
            cnt1 += 1
            cd.remove(j)
            break
tmp1.sort(key = lambda x:x[1])
tmp2.sort(key = lambda x:x[1])
ab = tmp1[:]
cd = tmp2[:]
for i in ab:
    for j in cd:
        if i[0] < j[0] and i[1] < j[1]:
            cnt2 += 1
            cd.remove(j)
            break
print(max(cnt1,cnt2))

Submission status: Wrong Answer

Solution code:
N = int(input())
r = [[int(i) for i in input().split()] for i in range(N)]
b = [[int(i) for i in input().split()] for i in range(N)]
r.sort(key=lambda x:(x[0],x[1]))
b.sort(key=lambda x:(x[0],x[1]))
ans = [0 for i in range(2)] 
for i in range(N):
    if r[ans[0]][0]<b[i][0] and r[ans[0]][1]<b[i][1]:
        ans[0] += 1
r.sort(key=lambda x:(x[1],x[0]))
b.sort(key=lambda x:(x[1],x[0]))
for i in range(N):
    if r[ans[1]][0]<b[i][0] and r[ans[1]][1]<b[i][1]:
        ans[1] += 1

print(max(ans))

Submission status: Wrong Answer

Solution code:
from operator import itemgetter
N = int(input())
r = [[int(i) for i in input().split()] for i in range(N)]
b = [[int(i) for i in input().split()] for i in range(N)]
r.sort()
b.sort()
ans = [0 for i in range(3)] 
for i in range(N):
    if r[ans[0]][0]<b[i][0] and r[ans[0]][1]<b[i][1]:
        ans[0] += 1
r.sort(key=itemgetter(1))
b.sort(key=itemgetter(1))
for i in range(N):
    if r[ans[1]][0]<b[i][0] and r[ans[1]][1]<b[i][1]:
        ans[1] += 1
r.sort(key=lambda x:(x[0]**2+x[1]**2))
b.sort(key=lambda x:(x[0]**2+x[1]**2))
for i in range(N):
    if r[ans[2]][0]<b[i][0] and r[ans[2]][1]<b[i][1]:
        ans[2] += 1

print(max(ans))

Submission status: Wrong Answer

Solution code:
def dfs(x,c,ans):
    if x==N:
        ans.append(c)
        return
    for i in range(N):
        if r[c][0]<b[i][0] and r[c][1]<b[i][1] and not used[i]:
            used[i] = True
            dfs(x+1,c+1,ans)
            used[i] = False
    dfs(x+1,c,ans)

N = int(input())
r = [[int(i) for i in input().split()] for i in range(N)]
b = [[int(i) for i in input().split()] for i in range(N)]
used = [False for i in range(N)]
ans = []
dfs(0,0,ans)
print(max(ans))

Submission status: Wrong Answer

Solution code:
from operator import itemgetter
N = int(input())
r = [[int(i) for i in input().split()] for i in range(N)]
b = [[int(i) for i in input().split()] for i in range(N)]
r.sort()
b.sort()
ansx = 0
for i in range(N):
    if r[ansx][0]<b[i][0] and r[ansx][1]<b[i][1]:
        ansx += 1
r.sort(key=itemgetter(1))
b.sort(key=itemgetter(1))
ansy = 0
for i in range(N):
    if r[ansy][0]<b[i][0] and r[ansy][1]<b[i][1]:
        ansy += 1

print(max(ansx,ansy))

Submission status: Wrong Answer

Solution code:
from operator import itemgetter
N = int(input())
r = [[int(i) for i in input().split()] for i in range(N)]
b = [[int(i) for i in input().split()] for i in range(N)]
r.sort()
b.sort()
ansx = 0
for i in range(N):
    if r[ansx][0]<b[i][0] and r[ansx][1]<b[i][1]:
        ansx += 1
r.sort(key=itemgetter(1))
b.sort(key=itemgetter(1))
ansy = 0
for i in range(N):
    if r[ansy][0]<b[i][0] and r[ansy][1]<b[i][1]:
        ansy += 1

Submission status: Wrong Answer

Solution code:
n = int(input())
# ablist = []
# for i in range(n):
#     ablist.append(list)
ablist = [list(map(int, input().split())) for i in range(n)]
cdlist = [list(map(int, input().split())) for i in range(n)]
ablist.sort()
cdlist.sort()

abflag = [False for i in range(n)]
cdflag = [False for i in range(n)]

for i in range(n - 1, -1, -1):
    candidate = (-1, -1)
    c_index = None
    for j in range(n - 1, -1, -1):
        if abflag[j] or cdflag[i]:
            continue
        
        a, b = ablist[j]
        c, d = cdlist[i]
        if a < c and b < d:
            if candidate[1] < b:
                candidate = (a, b)
                c_index = j
    if not (candidate == (-1, -1)):
        abflag[c_index] = True
        cdflag[i] = True

# print(abflag)
# print(cdflag)

print(len([flag for flag in abflag if flag == True]))

Submission status: Wrong Answer

Solution code:
n=int(input())
r=[list(map(int,input().split())) for i in range(n)]
bl=[list(map(int,input().split())) for i in range(n)]
rg=[0 for i in range(n)]
blg=[0 for i in range(n)]
for i in range(n):
    for j in range(n):
        a,b=r[i]
        c,d=bl[j]
        if a<c and b<d:
            rg[i]+=1
            blg[j]+=1
ir=0
for i in range(n):
    if rg[i]!=0:
        ir+=1
ire=0
for j in range(n):
    if blg[j]!=0:
        ire+=1
print(min(ir,ire))