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:
from collections import defaultdict

n = int(input())

r = defaultdict(lambda :2*n)
b = defaultdict(lambda :0)

def maesyori(d,n):
    for i in range(n):
        x,y = list(map(int,input().split()))
        d[x] = y
    return d

r = maesyori(r,n)
b = maesyori(b,n)

b_order = sorted(b.keys(), reverse = True)
r_order = sorted(r.keys(), reverse = True)

pair = 0

for i in b_order:
    for j in r_order:
        if i > j and b[i] > r[j]:
            pair += 1
            b[i] = 0
            r[j] = 2*n
             
print(pair)

Submission status: Wrong Answer

Solution code:
from collections import Counter
import math
n = int(input())
a = []
b = []
c = []
d = []
lis = []
li = []
nu = 0
for i in range(n):
    an,bn = map(int,input().split())
    a.append(an)
    b.append(bn)
for i in range(n):
    cn,dn = map(int,input().split())
    c.append(cn)
    d.append(dn)
for i in range(n):
    cou = 0
    for m in range(n):
        if a[i] < c[m] and b[i] < d[m]:
            cou += 1
    lis.append(cou)
lis.sort()
ans = 0

while min(lis) != 500:
    ans += min(min(lis),lis.count(min(lis)))
    aa = min(lis)
    for h in range(0,len(lis)):
        if lis[h] != 500:
            lis[h] -= aa
            if lis[h] <= 0:
                lis[h] = 500
    lis.sort()
print(ans)

Submission status: Wrong Answer

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

R = sorted(R)
B = sorted(B)
print(R, '\n', B, sep='')

res = 0
for r in R:
    mark = 0
    p = 0
    for i in range(len(B)):
        if r[0] <= B[i][0]:
            mark = i
            p = 1
            break
    if p == 0:
        continue
        
    temp1 = B[mark:]
    temp2 = []
    
    for x, y in temp1:
        temp2.append(y)

    j = temp2.index(min(temp2))
    
    B[mark+j][0], B[mark+j][1] = -1, -1
    res += 1

Submission status: Wrong Answer

Solution code:
class Point(object):
    def __init__(self, p_tuple):
        self.x = p_tuple[0]
        self.y = p_tuple[1]
        self.pair = False

N = int(input())
ab_list = sorted([Point(list(map(int, input().split()))) for _ in range(N)], key=lambda k: [k.y, k.x])
cd_list = sorted([Point(list(map(int, input().split()))) for _ in range(N)], key=lambda k: [k.y, k.x])
pair1 = 0
for ab in ab_list:
    for cd in cd_list:
        if ab.x< cd.x and ab.y < cd.y and not(ab.pair or cd.pair):
            pair1 += 1
            ab.pair = cd.pair = True
for ab, cd in zip(ab_list, cd_list):
    ab.pair = False
    cd.pair = False
ab_list = sorted(ab_list, key=lambda k: [k.x, k.y])
cd_list = sorted(cd_list, key=lambda k: [k.x, k.y])
pair2 = 0
for ab in ab_list:
    for cd in cd_list:
        if ab.x< cd.x and ab.y < cd.y and not(ab.pair or cd.pair):
            pair2 += 1
            ab.pair = cd.pair = True
print(pair1 if pair1 > pair2 else pair2)

Submission status: Wrong Answer

Solution code:
n=int(input())
ab=[]
for _ in range(n):
    a,b=map(int,input().split())
    ax=[a*b]
    ax.extend([False])
    ab.append(ax)
cd=[]
for _ in range(n):
    c,d=map(int,input().split())
    cx=[c*d]
    cx.extend([False])
    cd.append(cx)
ans=0
sab=sorted(ab)
scd=sorted(cd)
for a in sab:
    for c in scd:
        if a[0]<c[0] and c[1]==False:
            ans+=1
            c[1]=True
            break
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
blue = []
red = []
for n in range(N):
    red.append(list(map(int, input().split())))
for n in range(N):
    blue.append(list(map(int, input().split())))
    
sorted(blue, key=lambda x:(x[0],x[1]), reverse=True)
sorted(red, key=lambda x:(x[0],x[1]), reverse=True)

pear = 0
for r in red:
    for i,b in enumerate(blue):
        if r[0] < b[0] and r[1] < b[1]:
            pear +=1
            blue.pop(i)

print(pear)

Submission status: Wrong Answer

Solution code:
N = int(input())
R = []
for i in range(N):
    a, b = map(int, input().split())
    R.append([a, b])
B = []
for i in range(N):
    c, d = map(int, input().split())
    B.append([c, d])
R.sort()
R.reverse
B.sort()
B.reverse

ans = 0
for r in R:
    an = []
    for b in B:
        if (r[0] < b[0]) and (r[1] < b[1]):
            if len(an) == 0:
                an = b
            else:
                if min(an) > min(b):
                    an = b
    if len(an) != 0:
        ans += 1
        B.remove(an)


print(ans)

Submission status: Wrong Answer

Solution code:
import math
import sys
from pprint import pprint

def distance(a,b):
    return math.sqrt((a[0]-b[0])**2 + (a[1]-b[1])**2)

if __name__ == '__main__':
    N = int(input())
    reds = []
    for i in range(N):
        a,b = list(map(lambda x: int(x), input().split(" ")))
        reds.append((a,b))
    blues = []
    for i in range(N):
        c,d = list(map(lambda x: int(x), input().split(" ")))
        blues.append((c,d))
    ans = []
    reds.sort()
    blues.sort()
    while len(blues) != 0:
        for blue in blues:
            # pprint(reds)
            # pprint(blues)
            # print("------")
            red_ans = reds[0]
            min_d = sys.maxsize
            for red in reds:
                if blue[0] > red[0] and blue[1] > red[1] and (blue, red) not in ans:
                    d = distance(blue, red)
                    if min_d > d:
                        red_ans = red
                        min_d = d
            ans.append((blue, red_ans))
            blues.remove(blue)
            reds.remove(red_ans)
    print(len(ans))
    # while len(blues) == 0:
    #     blue = blues.pop()

Submission status: Wrong Answer

Solution code:




def main():
    co=0
    co1=0
    colist=[0]*100
    n=input()
    n=int(n)
    l1=[]
    l2=[]
    for i in range(n):
        temp=input()
        temp=list(map(int,list(temp.split(" "))))
        l1.append(temp)

    for j in range(n):
        temp=input()
        temp=list(map(int,list(temp.split(" "))))
        l2.append(temp)

  

    l1=sorted(l1, key=lambda x: x[0])
    l2=sorted(l2, key=lambda x: x[0])
    p=0
    # print(l1)
    # print(l2)
    for l in l1:
        for j in range(p,len(l2)):
            if l[0]<l2[j][0] and l[1]<l2[j][1]:
                co+=1
                p=j+1
                break

    l1=sorted(l1, key=lambda x: x[1])
    l2=sorted(l2, key=lambda x: x[1])
    p=0
    # print(l1)
    # print(l2)
  
    for l in l1:
        for j in range(p,len(l2)):
            if l[0]<l2[j][0] and l[1]<l2[j][1]:
                co1+=1
                p=j+1
                break
    print(max(co,co1))


    
    # for i in l1:
    #     temp=[]
    #     for num,j in enumerate(l2):
    #         if l1[0]<l2[0] and l1[1]<l2[1]:
    #             colist[j]+=1
    #             temp.append(j)
    




if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import copy
n = int(input())
x = [[int(i) for i in input().split()] for  i in range(n)]
y = [[int(i) for i in input().split()] for  i in range(n)]
x.sort()
y.sort()
y2 = copy.deepcopy(y)
answer1,answer2 = 0,0
for i in x:
	for j in range(len(y)):
		if i[0]<y[j][0] and i[1]<y[j][1]:
			answer1 += 1
			y = y[j+1:]
			break
for i in range(n):
	x[i][0],x[i][1],y2[i][0],y2[i][1] = x[i][1],x[i][0],y2[i][1],y2[i][0]
x.sort()
y2.sort()
for i in x:
	for j in range(len(y2)):
		if i[0]<y2[j][0] and i[1]<y2[j][1]:
			answer2 += 1
			y2 = y2[j+1:]
			break
print(max(answer1,answer2))

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 = sorted(ab,key=lambda x:x[0],reverse=True)
cd = sorted(cd,key=lambda x:x[0])
ab = sorted(ab,key=lambda x:x[0]+x[1],reverse=True)
cd = sorted(cd,key=lambda x:x[0]+x[1])


count = 0
for i in range(N):
    for j in range(len(cd)):
        if ab[i][0] < cd[j][0] and ab[i][1] < cd[j][1]:
            count += 1
            del cd[j]
            break

print(count)

Submission status: Wrong Answer

Solution code:
# -- coding: utf-8 --
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(' '))))
mred = sorted(red)
mblue = sorted(blue, reverse=True)
count = 0
for i in range(N):
    last = mred.pop()
    for num, l in enumerate(mblue[:]):
        if last[0] < l[0] and last[1] < l[1]:
            count += 1
            mblue.pop(num)
            break
print(count)

Submission status: Wrong Answer

Solution code:
n=int(input())
x=[]
for i in range(n):
	a=list(map(int,input().split()))
	x.append(a)
y=[]
for i in range(n):
	a=list(map(int,input().split()))
	y.append(a)
m=list(sorted(x,key=lambda x:x[0]))
l=list(sorted(x,key=lambda x:x[1]))
o=sorted(y,key=lambda y:y[0])
p=sorted(y,key=lambda y:y[1])
ma=0
i=0
j=0
e=0
while(i<n and j<n):
	if(m[i][0]<o[j][0] and m[i][1]<o[j][1]):
		e+=1
		i+=1
		j+=1
	elif(m[i][0]>=o[j][0] or m[i][1]>=o[j][1]):
		j+=1
if(ma<e):
	ma=e
i=0
j=0
e=0
while(i<n and j<n):
	if(l[i][0]<p[j][0] and l[i][1]<p[j][1]):
		e+=1
		i+=1
		j+=1
	elif(l[i][0]>=p[j][0] or l[i][1]>=p[j][1]):
		j+=1
if(ma<e):
	ma=e
print(ma)

Submission status: Wrong Answer

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

d = {}
for i in blue:
	d[i] = []
	x = i[0];
	y = i[1];
	for j in red:
		if j[0] < x and j[1] < y:
			d[i].append(j);

dd = d.values()

dd.sort(key = len)

dele = {}
for i in red:
	dele[i] = 0;

#print dd
#print dele;
for i in dd:
	for j in i:
		if dele[j] == 0:
			dele[j] = 1;
			break;
ans = 0;
for i in dele:
	if dele[i] == 1:
		ans+=1;
print ans

Submission status: Wrong Answer

Solution code:
#coding:utf-8
n = int(input())
a = []
b = []
for i in range(n):
    ai, bi = list(map(int, input().split()))
    a.append(ai)
    b.append(bi)

pair = 0
for i in range(n):
    c, d = list(map(int, input().split()))
    for j in range(n):
        if a[j] < c and b[j] < d:
            pair += 1
            break
print(pair)

Submission status: Wrong Answer

Solution code:
N = int(input())
R = []
for i in range(N):
    a, b = map(int, input().split())
    R.append([a, b])
B = []
for i in range(N):
    c, d = map(int, input().split())
    B.append([c, d])
R.sort()
B.sort()

ans = 0
for r in R:
    an = []
    for b in B:
        if (r[0] < b[0]) and (r[1] < b[1]):
            if len(an) == 0:
                an = b
            else:
                if min(an) > min(b):
                    an = b
    if len(an) != 0:
        ans += 1
        B.remove(an)


print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8

red = []
blue = []

# input
N = int(input())
# red
for i in range(N):
    a, b = map(int, input().split())
    red.append([a, b])
# blue
for i in range(N):
    c, d = map(int, input().split())
    blue.append([c, d])

# solve
count = 0
for i in range(N):
    # check x
    if (red[i][0] < blue[i][0] or red[i][1] < blue[i][1]):
        count += 1

print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = []
b = []
c = []
d = []
count = 0
for i in range(n):
    a_ad, b_ad = map(int, input().split())
    a.append(a_ad)
    b.append(b_ad)
for i in range(n):
    c_ad, d_ad = map(int, input().split())
    c.append(c_ad)
    d.append(d_ad)
sort_a = sorted(a, reverse = True)
for i in range(n):
    ind_a = a.index(sort_a[i])
    l = len(c)
    for k in range(l):
        if a[ind_a] < c[k] and b[ind_a] < d[k]:
            count += 1
            c = c[:k] + c[k+1:]
            d = d[:k] + d[k+1:]
            break
print(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 = sorted(ab,key=lambda x:x[0],reverse=True)
cd = sorted(cd,key=lambda x:x[0])
ab = sorted(ab,key=lambda x:x[1],reverse=True)
cd = sorted(cd,key=lambda x:x[1])


count = 0
for i in range(N):
    for j in range(len(cd)):
        if ab[i][0] < cd[j][0] and ab[i][1] < cd[j][1]:
            count += 1
            del cd[j]
            break

print(count)

Submission status: Wrong Answer

Solution code:
N=input()
a=[]
for i in range(2*N):
	x,y=map(int, raw_input().split())
	if i<N: a.append([x,y,"R"])
	else: a.append([x,y,"B"])

b=sorted(a, key=lambda x: x[0], reverse=True)

n=0
ans=0
for i in b:
	if i[2]=="B":
		n+=1
	else:
		n-=1
		if n>=0:
			ans+=1
print ans

Submission status: Wrong Answer

Solution code:
# coding: utf-8

red = []
blue = []

# input
N = int(input())
# red
for i in range(N):
    a, b = map(int, input().split())
    red.append([a, b])
# blue
for i in range(N):
    c, d = map(int, input().split())
    blue.append([c, d])

# solve
count = 0
for i in range(N):
    # check x
    if (red[i][0] < blue[i][0] and red[i][1] < blue[i][1]):
        count += 1
print(count)

Submission status: Wrong Answer

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

N = int(input())
R = [list(map(int, input().split(" "))) for _ in range(N)]
B = [list(map(int, input().split(" "))) for _ in range(N)]
R.sort(key=lambda x:(x[0],x[1]), reverse=True)
B.sort(key=lambda x:(x[0],x[1]), reverse=True)
R = deque(R)
B = deque(B)

pair = 0
while R:
    r = R.popleft()
    for b in B:
        if r[0]<b[0] and r[1]<b[1]:
            pair += 1
            B.popleft()
            break
    
print(pair)

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())))
an=sorted(a,reverse=True)
bn=sorted(b,reverse=True)
count=0
for i in range(len(bn)):
    for j in range(len(an)):
#        print(an[j],bn[i])
        if bn[i][0]>an[j][0] and bn[i][1]>an[j][1]:
            count+=1
            an.pop(j)
            break

print(count)

Submission status: Wrong Answer

Solution code:
n=int(input())
ab=[]
for _ in range(n):
    ax=list((map(int,input().split())))
    ax.extend([False])
    ab.append(ax)
cd=[]
for _ in range(n):
    cx=list(map(int,input().split()))
    cx.extend([False])
    cd.append(cx)
ans=0
sba=sorted(ab,key=lambda x:x[0]**2+x[1]**2,reverse=True)
scd=sorted(cd,key=lambda x:x[0]**2+x[1]**2,reverse=True)
for a in sba:
    for c in scd:
        if a[0]<c[0] and a[1]<c[1] and c[2]==False:
            ans+=1
            c[2]=True
            break
print(ans)

Submission status: Wrong Answer

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

pear = 0
for b,r in zip(blue,red):
    if r < b:
        pear +=1

print(pear)

Submission status: Wrong Answer

Solution code:
N=int(input())
Red=[[0,0,0]]*N

for i in range(N):
	a,b=input().split()
	Red[i] = [(int(a)+int(b)),int(a),int(b)]

Blue=[[0,0,0]]*N
for i in range(N):
	a,b=input().split()
	Blue[i]=[(int(a)+int(b)),int(a),int(b)]

Red.sort()
Blue.sort()

ans=0
for i in range(N):
	for k in range(N):
		if Red[i][0] < Blue[k][0]:
			if Red[i][1] < Blue[k][1]:
				ans += 1
				Blue[k][0] = 0
				Red[i][0] = Blue[N-1][0]+1
print(ans)

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())))
an=sorted(a,reverse=True)
bn=sorted(b,reverse=True)
print(an,bn)
count=0
for i in range(len(bn)):
    for j in range(len(an)):
#        print(an[j],bn[i])
        if bn[i][0]>an[j][0] and bn[i][1]>an[j][1]:
            count+=1
            an.pop(j)
            break

print(count)

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

red.sort()
blue.sort()
bf=[]
cnt=0

for r in red:
    for i,b in enumerate(blue):
        if i not in bf and r[0]<b[0] and r[1]<b[1]:
            bf.append(i)
            cnt+=1
#            print(r,b,cnt)
            break
print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
R = []
for i in range(N):
    R.append(input().split())
    R[i].append(0)
R.sort(key=lambda x:(int(x[0]),int(x[1])))
R.reverse()

B = []
for i in range(N):
    B.append(input().split())
    B[i].append(0)
B.sort(key=lambda x:(int(x[0]),int(x[1])))
B.reverse()

a = 0
for i in range(N):
    for j in range(N):
        if int(R[j][0]) < int(B[i][0]) and int(R[j][1]) < int(B[i][1]) and R[j][2] == 0 and B[i][2] == 0:
            a += 1
            R[j][2] = 1
            B[i][2] = 1
            break

print(a)

Submission status: Wrong Answer

Solution code:
def hantei(r, b):
    if b[0] > r[0] and b[1] > r[1]:
        return True
    else:
        return False
    
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, key = lambda x:-x[0])
B = sorted(B, key = lambda x:-x[0])
ans = 0
for b in B:
    for i, r in enumerate(R):
        if b[0] > r[0] and b[1] > r[1]:
            R.pop(i)
            ans += 1
            break
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
red=[list(map(int,input().split())) for _ in range(n)]
blue=[list(map(int,input().split())) for _ in range(n)]
red.sort(reverse=True)
blue.sort()
c=0
for rx,ry in red:
    for i in range(len(blue)):
        if rx < blue[i][0] and ry < blue[i][1]:
            c+=1
            blue.pop(i)
            break

print(c)

Submission status: Wrong Answer

Solution code:
import copy

n = int(input())

red_array = []
for i in range(n):
    red_array.append([int(x) for x in input().split()])
red_array = sorted(red_array, key=lambda x: (x[0], x[1]), reverse=True)
red_array2 = sorted(red_array, key=lambda x: (x[1], x[0]), reverse=True)

blue_array = []
for i in range(n):
    blue_array.append([int(x) for x in input().split()])
blue_array = sorted(blue_array, key=lambda x: (x[0], x[1]), reverse=True)
blue_array2 = sorted(blue_array, key=lambda x: (x[1], x[0]), reverse=True)

res1 = 0
for blue in blue_array:
    for red in red_array:
        if blue[0] > red[0] and blue[1] > red[1]:
            red_array.remove(red)
            res1 += 1
            break

res2 = 0
for blue in blue_array2:
    for red in red_array2:
        if blue[0] > red[0] and blue[1] > red[1]:
            red_array2.remove(red)
            res2 += 1
            break

print(max(res1, res2))

Submission status: Wrong Answer

Solution code:
import copy

n = int(input())

red_array = []
for i in range(n):
    red_array.append([int(x) for x in input().split()])
red_array = sorted(red_array, key=lambda x:(x[0],x[1]))
red_array2 = sorted(red_array, key=lambda x:(x[1],x[0]))

blue_array = []
for i in range(n):
    blue_array.append([int(x) for x in input().split()])
blue_array = sorted(blue_array, key=lambda x: (x[0], x[1]))
blue_array2 = sorted(blue_array, key=lambda x: (x[1], x[0]))

res1 = 0
for blue in blue_array:
    for red in red_array:
        if blue[0] > red[0] and blue[1] > red[1]:
            red_array.remove(red)
            res1 += 1
            break

res2 = 0
for blue in blue_array2:
    for red in red_array2:
        if blue[0] > red[0] and blue[1] > red[1]:
            red_array2.remove(red)
            res2 += 1
            break


print(max(res1, res2))

Submission status: Wrong Answer

Solution code:
import copy

n = int(input())

red_array = []
for i in range(n):
    red_array.append([int(x) for x in input().split()])
red_array = sorted(red_array, key=lambda x:(x[0],x[1]), reverse=True)
red_array2 = sorted(red_array, key=lambda x:(x[1],x[0]), reverse=True)


blue_array = []
for i in range(n):
    blue_array.append([int(x) for x in input().split()])
blue_array = sorted(blue_array, key=lambda x: (x[0], x[1]), reverse=True)
blue_array2 = sorted(blue_array, key=lambda x: (x[1], x[0]), reverse=True)

res1 = 0
for blue in blue_array:
    for red in red_array:
        if blue[0] > red[0] and blue[1] > red[1]:
            red_array.remove(red)
            res1 += 1
            break

res2 = 0
for blue in blue_array2:
    for red in red_array2:
        if blue[0] > red[0] and blue[1] > red[1]:
            red_array2.remove(red)
            res1 += 1
            break


print(max(res1, res2))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = []
b = []
ans = 0
for i in range(0, n):
    a.append(list(map(int, input().split(" "))))
for i in range(0, n):
    b.append(list(map(int, input().split(" "))))
a.sort(reverse=True)
b.sort(reverse=True)
for i in range(0, len(a)):
    for j in range(0, len(b)):
        if a[i][0] < b[j][0] and a[i][1] < b[j][1]:
            ans += 1
            del b[j]
            break
print(ans)

Submission status: Wrong Answer

Solution code:
def func(array):
    global red
    ans = 0
    for a, b in red:
        flag = False
        for i in range(len(array)):
            c, d = array[i]
            if a < c and b < d:
                ans += 1
                flag = True
                break
        if flag:
            array.pop(i)
    return ans

N = int(input())
red = sorted(tuple(map(int, input().split())) for _ in range(N))
blue = [tuple(map(int, input().split())) for _ in range(N)]
blue_0 = sorted(blue)
blue_1 = sorted(blue, key=lambda x: x[1])
blue_2 = blue_0[::-1]
blue_3 = blue_1[::-1]
maxv = 0
for array in [blue_0, blue_1, blue_2, blue_3]:
    maxv = max(maxv, func(array))
print(maxv)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = []
b = []
ans = 0
for i in range(0, n):
    a.append(list(map(int, input().split(" "))))
for i in range(0, n):
    b.append(list(map(int, input().split(" "))))
a.sort(reverse=True)
b.sort(reverse=True)
for i in range(0, len(a)):
    for j in range(0, len(b)):
        if a[i] < b[j]:
            ans += 1
            del b[j]
            break
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
red = [[int(i) for i in input().split()] for j in range(n)]
blue = [[int(i) for i in input().split()] for j in range(n)]
blue = sorted(blue,key=min)
red = sorted(red,key=min)
usedRed= [False]*n 
usedBlue = [False]*n 
pairs = 0

for i,r in enumerate(red):
  for j,b in enumerate(blue):
    if usedRed[i] or usedBlue[j]:
      continue 
    if r[0]<b[0] and r[1]<b[1]:
      usedRed[i] = True 
      usedBlue[j] = True 
      pairs+=1
      
print(pairs)

Submission status: Wrong Answer

Solution code:
import copy

n = int(input())

red_array = []
for i in range(n):
    red_array.append([int(x) for x in input().split()])
red_array = sorted(red_array, key=lambda x:(x[0],x[1]))
red_array2 = sorted(red_array, key=lambda x:(x[1],x[0]))

blue_array = []
for i in range(n):
    blue_array.append([int(x) for x in input().split()])
blue_array = sorted(blue_array, key=lambda x: (x[0], x[1]))
blue_array2 = sorted(blue_array, key=lambda x: (x[1], x[0]))

res1 = 0
for blue in blue_array:
    for red in red_array:
        if blue[0] > red[0] and blue[1] > red[1]:
            red_array.remove(red)
            res1 += 1
            break

res2 = 0
res1 = 0
for blue in blue_array2:
    for red in red_array2:
        if blue[0] > red[0] and blue[1] > red[1]:
            red_array2.remove(red)
            res1 += 1
            break


print(max(res1, res2))

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
a = []
b = []
c = []
d = []
lis = []
li = []
ans = 0
for i in range(n):
    an,bn = map(int,input().split())
    a.append(an)
    b.append(bn)
for i in range(n):
    cn,dn = map(int,input().split())
    c.append(cn)
    d.append(dn)
for i in range(n):
    cou = 0
    for m in range(n):
        if a[i] < c[m] and b[i] < d[m]:
            cou += 1
    lis.append(cou)
print(max(lis))

Submission status: Wrong Answer

Solution code:
N = int(input())
red = sorted(tuple(map(int, input().split())) for _ in range(N))
blue = sorted(tuple(map(int, input().split())) for _ in range(N))
ans = 0
for a, b in red:
    flag = False
    for i in range(len(blue)):
        c, d = blue[i]
        if a < c and b < d:
            ans += 1
            flag = True
            break
    if flag:
        blue.pop(i)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
red = [[int(i) for i in input().split()] for j in range(n)]
blue = [[int(i) for i in input().split()] for j in range(n)]
usedRed= [False]*n 
usedBlue = [False]*n 

pairs = 0

for i,r in enumerate(red):
  for j,b in enumerate(blue):
    if usedRed[i] or usedBlue[j]:
      continue 
    if r[0]<b[0] and r[1]<b[1]:
      usedRed[i] = True 
      usedBlue[j] = True 
      pairs+=1
      
print(pairs)

Submission status: Time Limit Exceeded

Solution code:
from itertools import permutations

if __name__ == '__main__':
    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))

    AB = list(range(N))
    CD = list(range(N))
    ans = 0
    for ab in permutations(AB):
        for cd in permutations(CD):
            size = 0
            for i in range(N):
                if ans > (N-i) + size : break
                red = RED[ab[i]]
                blue = BLUE[cd[i]]
                if red[0] < blue[0] and red[1] < blue[1]:
                    size += 1
            ans = max(ans, size)
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
from itertools import permutations

if __name__ == '__main__':
    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))

    AB = list(range(N))
    CD = list(range(N))
    ans = 0
    for ab in permutations(AB):
        for cd in permutations(CD):
            size = 0
            for i in range(N):
                if N-i > N - size: break
                red = RED[ab[i]]
                blue = BLUE[cd[i]]
                if red[0] < blue[0] and red[1] < blue[1]:
                    size += 1
            ans = max(ans, size)
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
from itertools import permutations

if __name__ == '__main__':
    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))

    AB = list(range(N))
    CD = list(range(N))
    ans = 0
    for ab in permutations(AB):
        for cd in permutations(CD):
            size = 0
            for i in range(N):
                red = RED[ab[i]]
                blue = BLUE[cd[i]]
                if red[0] < blue[0] and red[1] < blue[1]:
                    size += 1
            ans = max(ans, size)
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
from itertools import permutations

if __name__ == '__main__':
    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))

    AB = list(range(N))
    CD = list(range(N))
    ans = 0
    for ab in permutations(AB):
        for cd in permutations(CD):
            size = 0
            for i in range(N):
                red = RED[ab[i]]
                blue = BLUE[cd[i]]
                if red[0] < blue[0] and red[1] < blue[1]:
                    size += 1
            ans = max(ans, size)
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
import collections, itertools, copy


class MaximumFlow:
    def ford_fulkerson(self, G, s, t):
        G = copy.deepcopy(G)

        def dfs(start, used):
            if start == t:
                return [start]
            for end, cap in G[start].items():
                if cap > 0 and end not in used:
                    used.add(end)
                    ret = dfs(end, used)
                    if ret:
                        return ret + [start]
            return []

        flow_value = 0
        flow_dict = collections.defaultdict(
            lambda: collections.defaultdict(int))
        while True:
            root = dfs(s, set([s]))
            if root:
                root = root[::-1]
                residue = min([G[a][b] for a, b in zip(root, root[1:])])
                flow_value += residue
                for a, b in zip(root, root[1:]):
                    if a in flow_dict:
                        if residue >= flow_dict[b][a]:
                            flow_dict[a][b] += residue - flow_dict[b][a]
                            del flow_dict[b][a]
                        else:
                            flow_dict[b][a] -= residue
                    else:
                        flow_dict[a][b] += residue
                    flow_dict[a][b]
                    G[a][b] -= residue
                    G[b][a] += residue
            else:
                if t in flow_dict:
                    del flow_dict[t]
                    return (flow_value, flow_dict)


N = int(input())
AB = [[int(_) for _ in input().split()] for _ in range(N)]
CD = [[int(_) for _ in input().split()] for _ in range(N)]
G = collections.defaultdict(lambda: collections.defaultdict(int))
for a, b in AB:
    G[-1][1000 * a + b] = 1
for c, d in CD:
    G[1000 * c + d][-2] = 1
for ab, cd in itertools.product(AB, CD):
    a, b = ab
    c, d = cd
    if a < c and b < d:
        G[1000 * a + b][1000 * c + d] = 1
flow_value, flow_dict = MaximumFlow().ford_fulkerson(G, -1, -2)
print(flow_value)