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=[]
cd=[]

for i in range(N):
    e,f=map(int,input().split())
    tmp=[e,f]
    ab.append(tmp)

for i in range(N):
    e,f=map(int,input().split())
    tmp=[e,f]
    cd.append(tmp)

ab.sort()
cd.sort()

ab.reverse()
cd.reverse()

ans=0

for i in range(N):
    L=len(cd)
    for j in range(L):
        if ab[i][0]<cd[j][0] and ab[i][1]<cd[j][1]:
            ans+=1
            del cd[j]
            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)]
ans = 0
red = sorted(red, key = lambda x:x[1] * -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)
print(ans)

Submission status: Wrong Answer

Solution code:

def main():
    n = int(input().strip())
    reds = [[int(i) for i in input().split()] for _ in range(n)]
    blues = [[int(i) for i in input().split()] for _ in range(n)]
    reds.sort(reverse=True)
    blues.sort(reverse=True)

    pairs0 = []
    pairs1 = []

    for x0, y0 in reds:
        found = False
        if (x0, y0) in pairs0:
            continue
        for x1, y1 in blues:
            if (x1, y1) not in pairs1 and x0 < x1 and y0 < y1:
                pairs0.append((x0, y0))
                pairs1.append((x1, y1))
                found = True
                break
        if found:
            continue

    print(len(pairs0))
    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:

def main():
    n = int(input().strip())
    reds = [[int(i) for i in input().split()] for _ in range(n)]
    blues = [[int(i) for i in input().split()] for _ in range(n)]
    reds.sort(reverse=True)
    blues.sort(reverse=True)

    pairs0 = []
    pairs1 = []

    for x0, y0 in reds:
        found = False
        for x1, y1 in blues:
            if (x1, y1) not in pairs1 and x0 < x1 and y0 < y1:
                pairs0.append((x0, y0))
                pairs1.append((x1, y1))
                found = True
                break
        if found:
            continue

    print(len(pairs0))
    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import numpy
import re
import math
from collections import deque, defaultdict
import itertools

def main():
	"""
	テストコード実行
	:return:
	"""
	"""
	二次元量同士を比較する最大二部マッチング、貪欲法で回答可能
	"""
	n = int(input())
	red = []
	blue = []
	rp = [0 for _ in range(n)] #赤い点がペアかどうか記録
	bp = [0 for _ in range(n)]  # 青い点がペアかどうか記録
	for _ in range(n):
		a, b = map(int, input().split())
		red.append([a, b])
	for _ in range(n):
		a, b = map(int, input().split())
		blue.append([a, b])
	red = sorted(red, key=lambda x: (x[0], -x[1]))
	blue = sorted(blue, key=lambda x: (x[0],x[1]))
	cnt = 0
	for i in range(n):
		for j in range(n):
			if red[i][0] < blue[j][0] and red[i][1] < blue[j][1] and rp[i] == 0 and bp[j] == 0: #まだペアになっていない赤い点が見つかった場合
				rp[i] = 1
				bp[j] = 1
				cnt += 1
				break
	print(cnt)

if __name__ == '__main__':
	main()

Submission status: Wrong Answer

Solution code:
import numpy
import re
import math
from collections import deque, defaultdict
import itertools

def main():
	"""
	テストコード実行
	:return:
	"""
	"""
	二次元量同士を比較する最大二部マッチング、貪欲法で回答可能
	"""
	n = int(input())
	red = []
	blue = []
	rp = [0 for _ in range(n)] #赤い点がペアかどうか記録
	bp = [0 for _ in range(n)]  # 青い点がペアかどうか記録
	for _ in range(n):
		a, b = map(int, input().split())
		red.append([a, b])
	for _ in range(n):
		a, b = map(int, input().split())
		blue.append([a, b])
	red = sorted(red, key=lambda x: (x[0], -x[1]))
	blue = sorted(blue, key=lambda x: (x[0],x[1]))
	print(red)
	print(blue)
	#print(p)
	cnt = 0
	for i in range(n):
		for j in range(n):
			if red[i][0] < blue[j][0] and red[i][1] < blue[j][1] and rp[i] == 0 and bp[j] == 0: #まだペアになっていない赤い点が見つかった場合
				rp[i] = 1
				bp[j] = 1
				cnt += 1
				break
	print(cnt)

if __name__ == '__main__':
	main()

Submission status: Wrong Answer

Solution code:
N=int(input())

RED=[None]*N

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

BLUE=[None]*N

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

GROUPRED=[[i,set()] for i in range(N)]
GROUPBLUE=[[i,set()] for i in range(N)]

for i in range(N):
    for j in range(N):
        if RED[i][0]<BLUE[j][0] and RED[i][1]<BLUE[j][1]:
            GROUPRED[i][1]=GROUPRED[i][1]|{j}
            GROUPBLUE[j][1]=GROUPBLUE[j][1]|{i}

            #print(GROUPRED,GROUPBLUE)

GROUPRED.sort(key=lambda x:len(x[1]))

score=0
#print(GROUPRED,"\n",GROUPBLUE)
i=0
while i<N:
    COST=[]
    
    if len(GROUPRED[i][1])==0:
        i+=1
        continue
    
    else:
        for j in GROUPRED[i][1]:
            COST+=[[j,len(GROUPBLUE[j][1])]]
            #print(j,COST)

        k=min(COST,key=lambda x:x[1])[0]
        #print(COST,k)
        score+=1

        for j in range(N):
            GROUPRED[j][1]=GROUPRED[j][1]-{k}
            GROUPBLUE[j][1]=GROUPBLUE[j][1]-{i}

        GROUPRED.sort(key=lambda x:len(x[1]))
        i+=1

        
print(score)

Submission status: Wrong Answer

Solution code:
n = int(input())
full = list()
counter = 0

for i in range(n*2):
    full.append(list(map(int,input().split())))
                
red,blue = full[:n],full[n:]
red = sorted(red ,reverse=True)
blue=sorted(blue)

for i in range(n):
    for j in range(n):
        if red[i][0]<=blue[j][0] and red[i][1]<=blue[j][1]:
            counter +=1
            red[i][0] = 101
            blue[j][0] = -101
            
print(counter)

Submission status: Wrong Answer

Solution code:
import random
from operator import itemgetter

N = int(input())
AB = []
for i in range(0,N):
	a,b = input().split()
	a_i = int(a)
	b_i = int(b)
	AB.append((a_i,b_i))

CD = []
for j in range(0,N):
	c,d = input().split()
	c_i = int(c)
	d_i = int(d)
	CD.append((c_i,d_i))

sorted(AB, key=itemgetter(1))
AB.reverse()
CD.sort()

count = 0
for n in range(0,N):
	for m in range(0,len(CD)):
		if((AB[n])[0]<(CD[m])[0] and (AB[n])[1]<(CD[m])[1]):
			count += 1
			del CD[m]
			break

print(count)

Submission status: Wrong Answer

Solution code:
import random
N = int(input())
AB = []
AB1 = []
for i in range(0,N):
	a,b = input().split()
	a_i = int(a)
	b_i = int(b)
	AB.append((a_i,b_i))
	AB1.append((b_i,a_i))

CD = []
CD1 = []
for j in range(0,N):
	c,d = input().split()
	c_i = int(c)
	d_i = int(d)
	CD.append((c_i,d_i))
	CD1.append((d_i,c_i))

AB.sort()
AB.reverse()
CD.sort()
CD.reverse()

count = 0
for n in range(0,N):
	for m in range(0,len(CD)):
		if((AB[n])[0]<(CD[m])[0] and (AB[n])[1]<(CD[m])[1]):
			count += 1
			del CD[m]
			break
			


AB1.sort()
AB1.reverse()
CD1.sort()
CD1.reverse()

count1 = 0
for n in range(0,N):
	for m in range(0,len(CD1)):
		if((AB1[n])[0]<(CD1[m])[0] and (AB1[n])[1]<(CD1[m])[1]):
			count1 += 1
			del CD1[m]
			break
			

count2 = 0
p=0
while (p<N):
	ABs = list(AB)
	CDs = list(CD)

	for m in range(0,len(CDs)):

		r = random.choice(ABs)
		if(r[0]<(CDs[m])[0] and (r[1]<(CDs[m])[1])):
			count2 += 1
			del CDs[m]
			ABs.remove(r)
			break
	p += 1

print(max(count,count1,count2))

Submission status: Wrong Answer

Solution code:
N = int(input())
AB = []
AB1 = []
for i in range(0,N):
	a,b = input().split()
	a_i = int(a)
	b_i = int(b)
	AB.append((a_i,b_i))
	AB1.append((b_i,a_i))

CD = []
CD1 = []
for j in range(0,N):
	c,d = input().split()
	c_i = int(c)
	d_i = int(d)
	CD.append((c_i,d_i))
	CD1.append((d_i,c_i))

AB.sort()
AB.reverse()
CD.sort()
CD.reverse()

count = 0
for n in range(0,N):
	for m in range(0,len(CD)):
		if((AB[n])[0]<(CD[m])[0] and (AB[n])[1]<(CD[m])[1]):
			count += 1
			del CD[m]
			break
			break


AB1.sort()
AB1.reverse()
CD1.sort()
CD1.reverse()

count1 = 0
for n in range(0,N):
	for m in range(0,len(CD1)):
		if((AB1[n])[0]<(CD1[m])[0] and (AB1[n])[1]<(CD1[m])[1]):
			count1 += 1
			del CD1[m]
			break
			break

print(max(count,count1))

Submission status: Wrong Answer

Solution code:
N = int(input())
AB = []

for i in range(0,N):
	a,b = input().split()
	a_i = int(a)
	b_i = int(b)
	AB.append((a_i,b_i))

CD = []
for j in range(0,N):
	c,d = input().split()
	c_i = int(c)
	d_i = int(d)
	CD.append((c_i,d_i))

AB.sort()
AB.reverse()
CD.sort()
CD.reverse()

count = 0
for n in range(0,N):
	for m in range(0,len(CD)):
		if((AB[n])[0]<(CD[m])[0] and (AB[n])[1]<(CD[m])[1]):
			count += 1
			del CD[m]
			break
			break
print(count)

Submission status: Wrong Answer

Solution code:
N=int(input())
blue=[]
red=[]
ans=0
gone=[]
target=""
pair=""
Flug=False

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

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



for k in range(N):
    target=""
    target=red[k]
    pair=[101,101]
    for i in range(N):
        
        if blue[i] not in gone:
            if target[0]<blue[i][0] and target[1]<blue[i][1] and min(pair[0],pair[1]) >min(blue[i][0],blue[i][1]):
                pair=blue[i]
                Flug=True
               
            

                
    if Flug== True:
        gone.append(pair)
        Flug=False
        
    
            
        
print(len(gone))

Submission status: Wrong Answer

Solution code:
n = int(input())
red = []
for i in range(n):
    red.append(list(map(int, input().split())))
blue = []
for i in range(n):
    blue.append(list(map(int, input().split())))
good = []
good_red = 0
for i in range(n):
    good_len = len(good)
    for j in range(n):
        if (red[i][0] < blue[j][0]) & (red[i][1] < blue[j][1]):
            good.append(blue[j])
    good_len_2 = len(good)
    if good_len_2 > good_len:
        good_red += 1
def get_unique_list(seq):
    seen = []
    return [x for x in seq if x not in seen and not seen.append(x)]
good_unique = get_unique_list(good)
if len(good_unique) <= good_red:
    print(len(good_unique))
else:
    print(good_red)

Submission status: Wrong Answer

Solution code:
# input
N = int(input())
lst_red = [list(map(int, input().split())) for i in range(N)]
lst_blue = [list(map(int, input().split())) for i in range(N)]

lst_red.sort()
lst_blue.sort()

count1 = 0
i_red, i_blue = 0, 0

while i_red < N and i_blue < N:
    if lst_red[i_red][0] < lst_blue[i_blue][0]:
        if lst_red[i_red][1] < lst_blue[i_blue][1]:
            count1 += 1
            i_red += 1
            i_blue += 1
        else: 
            i_red += 1
    else:
        i_blue += 1

tmp1, tmp2 = 0, 0

for i in range(N):
    tmp1 = lst_red[i][1]
    lst_red[i][1] = lst_red[i][0]
    lst_red[i][0] = tmp1

    tmp2 = lst_blue[i][1]
    lst_blue[i][1] = lst_blue[i][0]
    lst_blue[i][0] = tmp2

lst_red.sort()
lst_blue.sort()

count2 = 0
i_red, i_blue = 0, 0

while i_red < N and i_blue < N:
    if lst_red[i_red][0] < lst_blue[i_blue][0]:
        if lst_red[i_red][1] < lst_blue[i_blue][1]:
            count2 += 1
            i_red += 1
            i_blue += 1
        else: 
            i_red += 1
    else:
        i_blue += 1

if count1 < count2:
    print(count2)
else:
    print(count1)

Submission status: Wrong Answer

Solution code:
class point:
    def __init__(self,x,y):
        self.x = x
        self.y = y

if __name__ == '__main__':
    N = int(raw_input())
    red = []
    blue = []
    for i in range(N):
        x,y = map(int, raw_input().split())
        red.append(point(x,y))

    for i in range(N):
        x,y = map(int, raw_input().split())
        blue.append(point(x,y))


    blue = sorted(blue, key=lambda k: k.x)
    red = sorted(red, key=lambda k: k.y, reverse=True)
    red_check = [0] * N
    ans = 0
    for b in blue:
        red_pair = None
        is_check = True
        for i, r in enumerate(red):
            if b.x > r.x and is_check and red_check[i] == 0:
                red_pair = r
                is_check = False
                red_check[i] = 1

        if red_pair is not None:
            ans += 1

    print(ans)

Submission status: Wrong Answer

Solution code:
class point:
    def __init__(self,x,y):
        self.x = x
        self.y = y

if __name__ == '__main__':
    N = int(raw_input())
    red = []
    blue = []
    for i in range(N):
        x,y = map(int, raw_input().split())
        red.append(point(x,y))

    for i in range(N):
        x,y = map(int, raw_input().split())
        blue.append(point(x,y))

    blue_count = []
    for i in range(N):
        blue_count.append([j for j in range(N) if red[j].x < blue[i].x and red[j].y < blue[i].y])

    ans = 0
    while(1):
        min_num = 200
        min_idx = 200
        for i in range(N):
            if len(blue_count[i]) >= 1:
                if len(blue_count[i]) < min_num:
                    min_num = len(blue_count[i])
                    min_idx = i

        if min_num == 200 and min_idx == 200:
            break
        del_num = blue_count[min_idx][0]
        del blue_count[min_idx][0]
        ans += 1
        for i in range(N):
            if del_num in blue_count[i]:
                blue_count[i].remove(del_num)
        blue_count[min_idx] = []
    print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
red = sorted([[int(i) for i in input().split()] for i in range(N)])
blue = sorted([[int(i) for i in input().split()] for i in range(N)])
count = 0
friend = []
index = 0

# 青の配列を回してる
for i in range(N):
    for j in range(N):
        if blue[i][0] > red[j][0] and blue[i][1] > red[j][1]:
            if not friend:
                friend = red[j]
            else:
                if friend[0] < red[j][0] and friend[1] < red[j][1]:
                    friend = red[j]
                    index = j
                elif friend[1] < red[j][1]:
                    friend = red[j]
                    index = j
        if j == len(red)-1 and friend and friend[0]>=0:
            print(red[index], blue[i])
            red[index][0] = -1
            red[index][1] = -1
            blue[i][0] = -1
            blue[i][1] = -1
            count += 1

print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
red = sorted([[int(i) for i in input().split()] for i in range(N)])
blue = sorted([[int(i) for i in input().split()] for i in range(N)])
count = 0
friend = []
index = 0

# 青の配列を回してる
for i in range(N):
    for j in range(N):
        if blue[i][0] > red[j][0] and blue[i][1] > red[j][1]:
            if not friend:
                friend = red[j]
            else:
                if friend[0] < red[j][0] and friend[1] < red[j][1]:
                    friend = red[j]
                    index = j
        if j == len(red)-1 and friend and friend[0]>=0:
            print(red[index], blue[i])
            red[index][0] = -1
            red[index][1] = -1
            blue[i][0] = -1
            blue[i][1] = -1
            count += 1

print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
red = sorted([[int(i) for i in input().split()] for i in range(N)])
blue = sorted([[int(i) for i in input().split()] for i in range(N)])
count = 0
friend = []
index = 0

# 青の配列を回してる
for i in range(N):
    for j in range(N):
        if blue[i][0] > red[j][0] and blue[i][1] > red[j][1]:
            if not friend:
                friend = red[j]
            else:
                if friend[1] < red[j][1]:
                    friend = red[j]
                    index = j
        if j == len(red)-1 and friend and friend[0]>=0:
            print(red[index], blue[i])
            red[index][0] = -1
            red[index][1] = -1
            blue[i][0] = -1
            blue[i][1] = -1
            count += 1

print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
RP = [tuple(map(lambda x: int(x), input().split())) for _ in range(N)]
BP = [tuple(map(lambda x: int(x), input().split())) for _ in range(N)]

def main():
    rows = []
    for r in RP:
        row = []
        for b in BP:
            if r < b:
                row.append(hash(b))
        rows.append(row)

    ans = 0

    while rows:
        rows = list(filter(lambda row: len(row) > 0, rows))
        if not rows:
            break
        rows = sorted(rows, key=lambda row: len(row))
        popped_row = rows.pop(0)
        point = popped_row.pop(0)
        ans += 1
        for row in rows:
            if point in row:
                row.remove(point)
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
i = 0
red = []
while i < n:
    a, b = map(int, input().split(" "))
    red.append([a, b])
    i += 1

i = 0
blue = []
while i < n:
    a, b = map(int, input().split(" "))
    blue.append([a, b])
    i += 1

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



count = 0
for i in sorted_red:
    for j in sorted_blue:
        if i[0] < j[0] and i[1] < j[1]:
            count += 1
            sorted_blue.remove(j)
            #print(sorted_blue)
            break

print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
i = 0
red = []
while i < n:
    a, b = map(int, input().split(" "))
    red.append([a, b])
    i += 1

i = 0
blue = []
while i < n:
    a, b = map(int, input().split(" "))
    blue.append([a, b])
    i += 1

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

count = 0
for i in sorted_red:
    for j in sorted_blue:
        if i[0] < j[0] and i[1] < j[1]:
            count += 1
            sorted_blue.remove(j)
            print(sorted_blue)
            break

print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
i = 0
red = []
while i < n:
    a, b = map(int, input().split(" "))
    red.append([a, b])
    i += 1

i = 0
blue = []
while i < n:
    a, b = map(int, input().split(" "))
    blue.append([a, b])
    i += 1

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

count = 0
for i in sorted_red:
    for j in sorted_blue:
        if i[0] < j[0] and i[1] < j[1]:
            count += 1
            sorted_blue.remove(j)

print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
red = sorted([list(map(int, input().split())) for _ in range(N)], key=lambda x: x[0], reverse=True)
blue = sorted([list(map(int, input().split())) for _ in range(N)], key=lambda x: x[0], reverse=True)
ans = 0
for b in blue:
    for i, r in enumerate(red):
        if b[0] > r[0] and b[1] > r[1]:
            ans += 1
            del red[i]
            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.sort()
B.sort()
count = 0
for i in range(N):
    for j in range(N):
        if R[i][0] < B[j][0] and R[i][1] < B[j][1]:
            count += 1
            R[i][0] = -1
            R[i][1] = -1
            B[j][0] = -2
            B[j][1] = -2
            break
print(count)

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(reverse=True)
blue_point.sort(reverse=True)
ans = 0
# print(red_point)
for i in range(N):
    redx,redy=red_point[i][0],red_point[i][1]
    for j in range(len(blue_point)):
        # print("({},{})".format(i,j))
        # print(blue_point)
        bluex,bluey=blue_point[j][0],blue_point[j][1]
        if redx<bluex and redy<bluey:
            ans +=1
            # red_point.pop(i)
            blue_point.pop(j)
            break
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

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

for _ in range(N):
    blue.append(list(map(int, input().split())))
    
match = []
for i in red:
    match.append([i[0]<j[0] and i[1]<j[1] for j in blue])

num = 0
while sum([sum(i) for i in match]) > 0:
    a = match.index(min(match))
    try:
        b = match[a].index(True)
    except ValueError:
        del match[a]
        continue
    del match[a]
    for i in match:
        i[b] = False
    num += 1
    
print(num)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = []
B = []
for i in range(N):
    u, v = map(int, input().split())
    A.append((u, v))
for i in range(N):
    u, v = map(int, input().split())
    B.append((u, v))
A.sort()
B.sort()
num = 0
for i in range(N):
    K = [A[k] for k in range(len(A)) if (A[k][0] <B[i][0]) and (A[k][1] < B[i][1])]
    if K:
        num += 1
        t = max(K)
        A.remove(t)
print(num)

Submission status: Wrong Answer

Solution code:
n = int(input())
ab = [list(map(int, input().split())) for i in range(n)]
cd = [list(map(int, input().split())) for i in range(n)]
ab = sorted(ab, reverse=True)
cd = sorted(cd)
ans = 0
for b in cd:
    for r in ab:
        if(r[0] < b[0] and r[1] < b[1]):
            ab.remove(r)
            ans += 1
            break
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
ab = [list(map(int, input().split())) for i in range(n)]
cd = [list(map(int, input().split())) for i in range(n)]
ab = sorted(ab)
cd = sorted(cd)
ans = 0
for b in cd:
    for r in ab:
        if(r[0] < b[0] and r[1] < b[1]):
            ab.remove(r)
            ans += 1
            break
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
red = []
blue = []
used_r = [False for _ in range(n)]
used_b = [False for _ in range(n)]
for i in range(n):
    tmp, tmp2 =  map(int, input().split())
    red.append((tmp,tmp2))
for i in range(n):
    tmp, tmp2 =  map(int, input().split())
    blue.append((tmp,tmp2))
red = sorted(red, key=lambda x: -1*x[1])
blue = sorted(blue)
print(red)
print(blue)
cnt = 0
for j in range(n):
    for i in range(n):
        if red[i][0] < blue[j][0] and red[i][1] < blue[j][1]:
            if used_r[i] or used_b[j]:
                continue
            else:
                cnt += 1
                used_r[i] = True
                used_b[j] = True
                break
print(cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
red = []
blue = []
used_r = [False for _ in range(n)]
used_b = [False for _ in range(n)]
for i in range(n):
    tmp, tmp2 =  map(int, input().split())
    red.append((tmp,tmp2))
for i in range(n):
    tmp, tmp2 =  map(int, input().split())
    blue.append((tmp,tmp2))
cnt = 0
for j in range(n):
    max_y = -1
    max_index = (-1,-1)
    for i in range(n):
        if used_r[i] or used_b[j]:
            continue
        if red[i][0] < blue[j][0] and red[i][1] < blue[j][1]:
            if max_y < red[i][1]:
                max_y = red[i][1]
                max_index = (i, j)
    if max_index != (-1, -1):
        cnt += 1
        used_r[max_index[0]] = True
        used_b[max_index[1]] = True
        print(max_index)
print(cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
red = []
blue = []
used_r = [False for _ in range(n)]
used_b = [False for _ in range(n)]
for i in range(n):
    tmp, tmp2 =  map(int, input().split())
    red.append((tmp,tmp2))
for i in range(n):
    tmp, tmp2 =  map(int, input().split())
    blue.append((tmp,tmp2))
red = sorted(red)
blue = sorted(blue)
cnt = 0
for i in range(n):
    for j in range(n):
        if red[i][0] < blue[j][0] and red[i][1] < blue[j][1]:
            if used_r[i] or used_b[j]:
                continue
            else:
                cnt += 1
                used_r[i] = True
                used_b[j] = True
                break

cnt2 = 0
red = sorted(red, reverse = True)
blue = sorted(blue, reverse = True)
used_r = [False for _ in range(n)]
used_b = [False for _ in range(n)]
for i in range(n):
    for j in range(n):
        if red[i][0] < blue[j][0] and red[i][1] < blue[j][1]:
            if used_r[i] or used_b[j]:
                continue
            else:
                cnt2 += 1
                used_r[i] = True
                used_b[j] = True
                break
print(max(cnt,cnt2))

Submission status: Wrong Answer

Solution code:
n = int(input())
red = []
blue = []
used_r = [False for _ in range(n)]
used_b = [False for _ in range(n)]
for i in range(n):
    tmp, tmp2 =  map(int, input().split())
    red.append((tmp,tmp2))
for i in range(n):
    tmp, tmp2 =  map(int, input().split())
    blue.append((tmp,tmp2))
red = sorted(red, key=lambda x:min(x))
blue = sorted(blue, key=lambda x:min(x))
cnt = 0
for i in range(n):
    for j in range(n):
        if red[i][0] < blue[j][0] and red[i][1] < blue[j][1]:
            if used_r[i] or used_b[j]:
                continue
            else:
                cnt += 1
                used_r[i] = True
                used_b[j] = True
                break

cnt2 = 0
blue = sorted(blue, key=lambda x:max(x))
used_r = [False for _ in range(n)]
used_b = [False for _ in range(n)]
for i in range(n):
    for j in range(n):
        if red[i][0] < blue[j][0] and red[i][1] < blue[j][1]:
            if used_r[i] or used_b[j]:
                continue
            else:
                cnt2 += 1
                used_r[i] = True
                used_b[j] = True
                break
print(max(cnt,cnt2))

Submission status: Wrong Answer

Solution code:
n = int(input())
red = []
blue = []
used_r = [False for _ in range(n)]
used_b = [False for _ in range(n)]
for i in range(n):
    tmp, tmp2 =  map(int, input().split())
    red.append((tmp,tmp2))
for i in range(n):
    tmp, tmp2 =  map(int, input().split())
    blue.append((tmp,tmp2))
red = sorted(red, key=lambda x:min(x))
blue = sorted(blue, key=lambda x:min(x))
cnt = 0
for i in range(n):
    for j in range(n):
        if red[i][0] < blue[j][0] and red[i][1] < blue[j][1]:
            if used_r[i] or used_b[j]:
                continue
            else:
                cnt += 1
                used_r[i] = True
                used_b[j] = True
                break
print(cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
red = []
blue = []
used_r = [False for _ in range(n)]
used_b = [False for _ in range(n)]
for i in range(n):
    tmp, tmp2 =  map(int, input().split())
    red.append((tmp,tmp2))
for i in range(n):
    tmp, tmp2 =  map(int, input().split())
    blue.append((tmp,tmp2))
red = sorted(red, key=lambda x:min(x), reverse=True)
blue = sorted(blue, key=lambda x:min(x), reverse=True)
cnt = 0
for i in range(n):
    for j in range(n):
        if red[i][0] < blue[j][0] and red[i][1] < blue[j][1]:
            if used_r[i] or used_b[j]:
                continue
            else:
                cnt += 1
                used_r[i] = True
                used_b[j] = True
                break
print(cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
red = []
blue = []
used_r = [False for _ in range(n)]
used_b = [False for _ in range(n)]
for i in range(n):
    tmp, tmp2 =  map(int, input().split())
    red.append((tmp,tmp2))
for i in range(n):
    tmp, tmp2 =  map(int, input().split())
    blue.append((tmp,tmp2))
red = sorted(red, reverse=True)
blue = sorted(blue, reverse=True)
cnt = 0
for i in range(n):
    for j in range(n):
        if red[i][0] < blue[j][0] and red[i][1] < blue[j][1]:
            if used_r[i] or used_b[j]:
                continue
            else:
                cnt += 1
                used_r[i] = True
                used_b[j] = True
                break
print(cnt)

Submission status: Wrong Answer

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

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

for i in range(n):
    c, d = map(int,input().split())
    blue.append([c,d])
    
red_sort = list(reversed(sorted(red, key=lambda y: y[1])))
blue_sort = sorted(blue, key=lambda x: x[0])

# print(red_sort)
# [[1, 3], [2, 0], [3, 1]]
# print(blue_sort)
# [[4, 2], [0, 4], [5, 5]]

pair = []
for blue_point in blue_sort:
    x_blue = blue_point[0]
    y_blue = blue_point[1]
    one_l = []
    for red_point in red_sort:
        x_red = red_point[0]
        y_red = red_point[1]
        
        if x_red<x_blue and y_red<y_blue and one_l == []:
            one_l.append([x_red,y_red,x_blue,y_blue])
    if one_l != []:
        pair.append(one_l)
print(len(pair))

Submission status: Wrong Answer

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

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

for i in range(n):
    c, d = map(int,input().split())
    blue.append([c,d])
    
red_sort = list(reversed(sorted(red, key=lambda y: y[1])))
blue_sort = sorted(blue, key=lambda x: x[0])

# print(red_sort)
# [[1, 3], [2, 0], [3, 1]]
# print(blue_sort)
# [[4, 2], [0, 4], [5, 5]]

pair = []
for red_point in red_sort:
    x_red = red_point[0]
    y_red = red_point[1]
    one_l = []
    for blue_point in blue_sort:
        x_blue = blue_point[0]
        y_blue = blue_point[1]
        
        if x_red<x_blue and y_red<y_blue and one_l == []:
            one_l.append([x_red,y_red,x_blue,y_blue])
    if one_l != []:
        pair.append(one_l)
print(len(pair))

Submission status: Wrong Answer

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

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

for i in range(n):
    c, d = map(int,input().split())
    blue.append([c,d])
    
red_sort = list(reversed(sorted(red, key=lambda x: x[0])))
blue_sort = sorted(blue, key=lambda y: y[1])

# print(red_sort)
# [[1, 3], [2, 0], [3, 1]]
# print(blue_sort)
# [[4, 2], [0, 4], [5, 5]]

pair = []
for red_point in red_sort:
    x_red = red_point[0]
    y_red = red_point[1]
    one_l = []
    for blue_point in blue_sort:
        x_blue = blue_point[0]
        y_blue = blue_point[1]
        
        if x_red<x_blue and y_red<y_blue and one_l == []:
            one_l.append([x_red,y_red,x_blue,y_blue])
    if one_l != []:
        pair.append(one_l)
print(len(pair))