Problem:


Score : 400 points

Problem Statement

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

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

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

Constraints

All input values are integers.

1 \leq N \leq 100

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

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

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

Input

Input is given from Standard Input in the following format:

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

Output

Print the maximum number of friendly pairs.

Sample Input 1

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

Sample Output 1

2

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

Sample Input 2

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

Sample Output 2

2

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

Sample Input 3

2
2 2
3 3
0 0
1 1

Sample Output 3

0

It is possible that no pair can be formed.

Sample Input 4

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

Sample Output 4

5

Sample Input 5

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

Sample Output 5

4



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


Sample output:
2

Submission status: Wrong Answer

Solution code:
N = int(input())
R = [[int(i) for i in input().split()] for j in range(N)]
B = [[int(i) for i in input().split()] for j in range(N)]

red = sorted(R)
blue = sorted(B)
ans1 = 0
for a,b in red:
  flag = False
  for w in range(1,2*N):
    for h in range(1,2*N):
      if [a+w,b+h] in blue:
        ans1 += 1
        blue.remove([a+w,b+h])
        flag = True
      if flag:
        break
    if flag:
      break
blue = sorted(B)
ans2 = 0
for a,b in red:
  flag = False
  for h in range(1,2*N):
    for w in range(1,2*N):
      if [a+w,b+h] in blue:
        ans2 += 1
        blue.remove([a+w,b+h])
        flag = True
      if flag:
        break
    if flag:
      break
print(max(ans1,ans2))

Submission status: Wrong Answer

Solution code:
import copy

def main():
    N = int(input())
    abList = []
    cdList = []
    for i in range(N):
        [a, b] = list(map(int, input().split(' ')))
        abList.append( (-a-b, a, b) )
    for i in range(N):
        [c, d] = list(map(int, input().split(' ')))
        cdList.append( (c+d, c, d) )
    abList.sort()
    cdList.sort()
    cdList2 = copy.copy( cdList )
    ans = 0
    for (v, a, b) in abList:
        for i in range( len(cdList) ):
            (_, c, d) = cdList[i]
            if a <= c and b <= d:
                cdList.pop(i)
                ans += 1
                break
    ans2 = 0
    abList.reverse()
    for (v, a, b) in abList:
        for i in range( len(cdList2) ):
            (_, c, d) = cdList2[i]
            if a <= c and b <= d:
                cdList2.pop(i)
                ans2 += 1
                break
    print( max(ans, ans2) )
main()

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)
print(lis)
lis.sort()
ans = 0
print(lis)
while min(lis) != 500:
    print(min(lis),lis.count(min(lis)))
    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(lis)
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)
R = list(reversed(R))
B = sorted(B)

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

Submission status: Wrong Answer

Solution code:
N = int(input())
listRed = [[i for i in map(int,input().split())]for j in range(N)]
listBlue = [[i for i in map(int,input().split())]for j in range(N)]
ans = 0
sortRed = sorted(listRed,reverse=True)
sortBlue = sorted(listBlue,reverse=True)

for i in range(N):
    for j in range(len(sortBlue)):
        if sortRed[i][0] < sortBlue[j][0] and sortRed[i][1] < sortBlue[j][1]:
            ans += 1
            sortBlue.pop(j)
            break

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
red_list = []
x_min = 200
for i in range(n):
    x, y = map(int, input().split())
    x_min = min(x_min, x)
    red_list.append((x, y))
red_list = sorted(red_list)
blue_list = []
for i in range(n):
    x, y = map(int, input().split())
    if x_min < x:
        blue_list.append((x, y))
blue_list = sorted(blue_list, key=lambda x: x[1])

max_pair = min(len(red_list), len(blue_list))
pair = 0
for blue in blue_list:
    flag = 0
    p_x, p_y = 200, 200
    for red in red_list:
        if blue[0] > red[0] and blue[1] > red[1]:
            if p_x + p_y > (blue[0]-red[0]) + (blue[1]-red[1]):
                p_x = red[0]
                p_y = red[1]
                flag = 1
    if flag == 1:
        pair += 1
        red_list.remove((p_x, p_y))
    if pair >= max_pair:
        break

print(pair)

Submission status: Wrong Answer

Solution code:
N = int(input())
Flag = 0
TmpNum = 0
Count = 0
Red = [[0 for i in range(3)]  for j in range(N)]
Blue= [[0 for i in range(3)]  for j in range(N)]

for i in range(N):
    Tmp = input().rstrip().split(' ')
    Red[i][0] = int(Tmp[0])
    Red[i][1] = int(Tmp[1])
    Red[i][2] = Red[i][0]**2+Red[i][1]**2

for i in range(N):
    Tmp = input().rstrip().split(' ')
    Blue[i][0] = int(Tmp[0])
    Blue[i][1] = int(Tmp[1])
    Blue[i][2] = Blue[i][0]**2+Blue[i][1]**2

Red = sorted(Red, key=lambda x: x[2],  reverse=True)          
Blue = sorted(Blue, key=lambda x: x[2],  reverse=True)     
    
Count = 0
for i in range(N):
    TmpRx = Red[i][0]
    TmpRy = Red[i][1]
    
    for i2 in range(N):
        TmpBx = Blue[i2][0]
        TmpBy = Blue[i2][1]
        if TmpBx < 101:
            if (TmpRx < TmpBx) and (TmpRy < TmpBy):
                Count += 1
                Blue[i2][0] = 1000
                Blue[i2][1] = 1000
                Red[i][0] = 1000
                Red[i][1] = 1000
                break

print(Count)

Submission status: Wrong Answer

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

N = int(input())
ab = []
for i in range(0,N):
    data1,data2 = input().split()
    ab.append([int(data1),int(data2)])

cd = []
for i in range(0,N):
    data1,data2 = input().split()
    cd.append([int(data1),int(data2)])

ab_sort = sorted(ab)
cd_sort = sorted(cd)
ab_sort_r = sorted(ab)
ab_sort_r.reverse()
cd_sort_r = sorted(cd)
cd_sort_r.reverse()


pair1 = 0
del_list = []
for i in cd_sort_r:
    n = 0
    for j in ab_sort:
        if i[0] > j[0] and i[1] > j[1]:
            pair1 = pair1 + 1
            break
        else:
            n = n + 1
    if n < int(len(ab_sort)):
        del(ab_sort[n])



pair2 = 0
del_list = []
for i in cd_sort_r:
    n = 0
    for j in ab_sort_r:
        if i[0] > j[0] and i[1] > j[1]:
            pair2 = pair2 + 1
            break
        else:
            n = n + 1
    if n < int(len(ab_sort_r)):
        del(ab_sort_r[n])

if pair1 < pair2:
    print(pair2)
else:
    print(pair1)

Submission status: Wrong Answer

Solution code:
N = int(input())
red = [3*N] * (2*N)
blue = [-1] * (2*N)
for i in range(N):
    a, b = (int(j) for j in input().split())
    red[a] = b
for i in range(N):
    a, b = (int(j) for j in input().split())
    blue[a] = b
ans = 0
for i in range(1, 2*N):
    for j in range(blue[i]-1, -1, -1):
        if j in red:
            ans += 1
            blue[i] = 0
            red[red.index(j)] = 3 * N
            break
print(ans)

Submission status: Wrong Answer

Solution code:
import heapq
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)

q=[]
ans=0
for i in b:
	x=i[1]
	type=i[2]
	if type=="B":
		heapq.heappush(q,x*-1)
	else:
		if len(q)>0 and a[0]*-1>=x:
			heapq.heappop(q)
			ans+=1
print ans

Submission status: Wrong Answer

Solution code:
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

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

red.sort()
blue.sort()

ans = 0
for i in red:
    for j in blue:
        if i[0] < j[0] and i[1] < j[1]:
            ans += 1
            blue.remove(j)
            break
print(ans)

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],x[1]))
    l2=sorted(l2, key=lambda x: (x[0],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]:
                co+=1
                p=j+1
                break

    l1=sorted(l1, key=lambda x: (x[1],x[0]))
    l2=sorted(l2, key=lambda x: (x[1],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]:
                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:
N = int(input())
pairs = 0

a = [list(map(int,input().split())) for i in range(N)]
b = [list(map(int,input().split())) for i in range(N)]
btree = [{} for i in range(N)]


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

for i in range(len(b)):
    for a_point in a:
        if small(a_point,b[i]):
            btree[i][str(a_point[0])+" "+str(a_point[1])] = 1
length = 0
min_len = 1
for bt in btree:
    length += len(bt)
k = 0
f_length = length
while length > 0:
    key = 0
    for i in range(N):
        if len(btree[i]) == min_len:
            key += 1
            pairs += 1
            ke = list(btree[i].keys())
            length -= (len(btree[i]))
            btree[i] = {}
            for i in range(N):
                if str(ke[0]) in btree[i]:
                    del btree[i][str(ke[0])]
                    length -= 1
            min_len = 1
            break
    if key <= 0:
        min_len += 1

if f_length ==0:
    print(0)
else:
    print(pairs)

Submission status: Wrong Answer

Solution code:
N = int(input())
red = [3*N] * (2*N)
blue = [0] * (2*N)
for i in range(N):
    a, b = (int(j) for j in input().split())
    red[a] = b
for i in range(N):
    a, b = (int(j) for j in input().split())
    blue[a] = b
ans = 0
for i in range(1, 2*N):
    for j in range(blue[i]-1, -1, -1):
        if j in red:
            ans += 1
            blue[i] = 0
            red[red.index(j)] = 3 * N
print(ans)

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)]
Blue=[[0,0,0]]*N
for i in range(N):
	a,b=input().split()
	Blue[i]=[int(a),int(b)]
Red.sort()
Blue.sort()
ans=0
for i in range(N):
	for l in range(N):
		for k in range(N):
			if Blue[k][0] == Red[i][0] + l or Blue[k][1] == Red[i][1] + l:
				if Red[i][0] < Blue[k][0] and 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())
R = [list(map(int, input().split())) for _ in range(N)]
B = [list(map(int, input().split())) for _ in range(N)]

R = sorted(R)
R = list(reversed(R))
B = sorted(B)
B = list(reversed(B))

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

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:
def main():
    N = int(input())
    abList = []
    cdList = []
    for i in range(N):
        [a, b] = list(map(int, input().split(' ')))
        abList.append( (-a-b, a, b) )
    for i in range(N):
        [c, d] = list(map(int, input().split(' ')))
        cdList.append( (c+d, c, d) )
    abList.sort()
    cdList.sort()
    ans = 0
    # print( abList )
    # print( cdList )
    for (v, a, b) in abList:
        for i in range( len(cdList) ):
            (_, c, d) = cdList[i]
            if a <= c and b <= d:
                # print(c, d)
                cdList.pop(i)
                ans += 1
                break
    print( ans )
main()

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.sort(reverse=True)
CD.sort(reverse=True)

AB_set = []
CD_set = []
for index_ab, ab in enumerate(AB):
    i, j = -1, -1
    if index_ab in AB_set:
        continue
    distance = float('inf')
    for index_cd, cd in enumerate(CD):
        if index_cd in CD_set:
            continue
        if (cd[0] - ab[0] >= 0) & (cd[1] - ab[1] >= 0) & ((cd[0]-ab[0]) + (cd[1] - ab[1]) < distance):
            distance = (cd[0] - ab[0]) + (cd[1] - ab[1])
            i, j = index_ab, index_cd
    if (i != -1) & (j != -1):
        AB_set.append(i)
        CD_set.append(j)

ans1 = len(AB_set)

AB.sort()
CD.sort()

AB_set = []
CD_set = []
for index_ab, ab in enumerate(AB):
    i, j = -1, -1
    if index_ab in AB_set:
        continue
    distance = float('inf')
    for index_cd, cd in enumerate(CD):
        if index_cd in CD_set:
            continue
        if (cd[0] - ab[0] >= 0) & (cd[1] - ab[1] >= 0) & ((cd[0]-ab[0]) + (cd[1] - ab[1]) < distance):
            distance = (cd[0] - ab[0]) + (cd[1] - ab[1])
            i, j = index_ab, index_cd
    if (i != -1) & (j != -1):
        AB_set.append(i)
        CD_set.append(j)

ans2= len(AB_set)

AB.sort(key=lambda x:x[1])
CD.sort(key=lambda x:x[1])

AB_set = []
CD_set = []
for index_ab, ab in enumerate(AB):
    i, j = -1, -1
    if index_ab in AB_set:
        continue
    distance = float('inf')
    for index_cd, cd in enumerate(CD):
        if index_cd in CD_set:
            continue
        if (cd[0] - ab[0] >= 0) & (cd[1] - ab[1] >= 0) & ((cd[0]-ab[0]) + (cd[1] - ab[1]) < distance):
            distance = (cd[0] - ab[0]) + (cd[1] - ab[1])
            i, j = index_ab, index_cd
    if (i != -1) & (j != -1):
        AB_set.append(i)
        CD_set.append(j)

ans3= len(AB_set)

AB.sort(key=lambda x:x[1], reverse=True)
CD.sort(key=lambda x:x[1], reverse=True)

AB_set = []
CD_set = []
for index_ab, ab in enumerate(AB):
    i, j = -1, -1
    if index_ab in AB_set:
        continue
    distance = float('inf')
    for index_cd, cd in enumerate(CD):
        if index_cd in CD_set:
            continue
        if (cd[0] - ab[0] >= 0) & (cd[1] - ab[1] >= 0) & ((cd[0]-ab[0]) + (cd[1] - ab[1]) < distance):
            distance = (cd[0] - ab[0]) + (cd[1] - ab[1])
            i, j = index_ab, index_cd
    if (i != -1) & (j != -1):
        AB_set.append(i)
        CD_set.append(j)

ans4= len(AB_set)
print(max(ans1, ans2, ans3, ans4))

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])
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:
import numpy as np

N=int(input())
A=[]
B=[]
T=[]
for i in range(N):
    a,b=map(int, input().split())
    A.append(a)
    B.append(b)
    T.append(min(a,b))
C=[]
D=[]
S=[]
for i in range(N):
    c,d=map(int, input().split())
    C.append(c)
    D.append(d)
    S.append(min(c,d))

Ts=sorted(T)
Ss=sorted(S)


p=0
for i in Ts:
    for j in Ss:
        if A[T.index(i)]<C[S.index(j)] and B[T.index(i)]<D[S.index(j)]:
            p+=1
            Ss.remove(j)
            break

print(p)

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_x = sorted([Point(list(map(int, input().split()))) for _ in range(N)], key=lambda k: [k.y, k.x])
cd_list_x = sorted([Point(list(map(int, input().split()))) for _ in range(N)], key=lambda k: [k.y, k.x])
ab_list_y = sorted(ab_list_x, key=lambda k: [k.y, k.x])
cd_list_y = sorted(ab_list_y, key=lambda k: [k.y, k.x])
pair1 = 0
for ab in ab_list_x:
    for cd in cd_list_x:
        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_x, cd_list_x):
    ab.pair = False
    cd.pair = False
pair2 = 0
for ab in ab_list_x:
    for cd in cd_list_y:
        if ab.x< cd.x and ab.y < cd.y and not(ab.pair or cd.pair):
            pair2 += 1
            ab.pair = cd.pair = True
for ab, cd in zip(ab_list_x, cd_list_y):
    ab.pair = False
    cd.pair = False
pair3 = 0
for ab in ab_list_y:
    for cd in cd_list_x:
        if ab.x< cd.x and ab.y < cd.y and not(ab.pair or cd.pair):
            pair3 += 1
            ab.pair = cd.pair = True
for ab, cd in zip(ab_list_y, cd_list_x):
    ab.pair = False
    cd.pair = False
pair4 = 0
for ab in ab_list_y:
    for cd in cd_list_y:
        if ab.x< cd.x and ab.y < cd.y and not(ab.pair or cd.pair):
            pair4 += 1
            ab.pair = cd.pair = True
print(max([pair1, pair2, pair3, pair4]))

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.sort(reverse=True)
CD.sort(reverse=True)

AB_set = []
CD_set = []
for index_ab, ab in enumerate(AB):
    i, j = -1, -1
    if index_ab in AB_set:
        continue
    distance = float('inf')
    for index_cd, cd in enumerate(CD):
        if index_cd in CD_set:
            continue
        if (cd[0] - ab[0] >= 0) & (cd[1] - ab[1] >= 0) & ((cd[0]-ab[0]) + (cd[1] - ab[1]) <= distance):
            distance = (cd[0] - ab[0]) + (cd[1] - ab[1])
            i, j = index_ab, index_cd
    if (i != -1) & (j != -1):
        AB_set.append(i)
        CD_set.append(j)

ans1 = len(AB_set)

AB.sort()
CD.sort()

AB_set = []
CD_set = []
for index_ab, ab in enumerate(AB):
    i, j = -1, -1
    if index_ab in AB_set:
        continue
    distance = float('inf')
    for index_cd, cd in enumerate(CD):
        if index_cd in CD_set:
            continue
        if (cd[0] - ab[0] >= 0) & (cd[1] - ab[1] >= 0) & ((cd[0]-ab[0]) + (cd[1] - ab[1]) <= distance):
            distance = (cd[0] - ab[0]) + (cd[1] - ab[1])
            i, j = index_ab, index_cd
    if (i != -1) & (j != -1):
        AB_set.append(i)
        CD_set.append(j)

ans2= len(AB_set)

AB.sort(key=lambda x:x[1])
CD.sort(key=lambda x:x[1])

AB_set = []
CD_set = []
for index_ab, ab in enumerate(AB):
    i, j = -1, -1
    if index_ab in AB_set:
        continue
    distance = float('inf')
    for index_cd, cd in enumerate(CD):
        if index_cd in CD_set:
            continue
        if (cd[0] - ab[0] >= 0) & (cd[1] - ab[1] >= 0) & ((cd[0]-ab[0]) + (cd[1] - ab[1]) <= distance):
            distance = (cd[0] - ab[0]) + (cd[1] - ab[1])
            i, j = index_ab, index_cd
    if (i != -1) & (j != -1):
        AB_set.append(i)
        CD_set.append(j)

ans3= len(AB_set)

AB.sort(key=lambda x:x[1], reverse=True)
CD.sort(key=lambda x:x[1], reverse=True)

AB_set = []
CD_set = []
for index_ab, ab in enumerate(AB):
    i, j = -1, -1
    if index_ab in AB_set:
        continue
    distance = float('inf')
    for index_cd, cd in enumerate(CD):
        if index_cd in CD_set:
            continue
        if (cd[0] - ab[0] >= 0) & (cd[1] - ab[1] >= 0) & ((cd[0]-ab[0]) + (cd[1] - ab[1]) <= distance):
            distance = (cd[0] - ab[0]) + (cd[1] - ab[1])
            i, j = index_ab, index_cd
    if (i != -1) & (j != -1):
        AB_set.append(i)
        CD_set.append(j)

ans4= len(AB_set)
print(max(ans1, ans2, ans3, ans4))

Submission status: Wrong Answer

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

N = int(input())
ab = []
for i in range(0,N):
    data1,data2 = input().split()
    ab.append([int(data1),int(data2)])

cd = []
for i in range(0,N):
    data1,data2 = input().split()
    cd.append([int(data1),int(data2)])

ab_sort = sorted(ab)
ab_sort.reverse()
cd_sort = sorted(cd)
cd_sort.reverse()

pair = 0
del_list = []
for i in cd_sort:
    n = 0
    for j in ab_sort:
        if i[0] > j[0] and i[1] > j[1]:
            pair = pair + 1
            break
        else:
            n = n + 1
    if n < int(len(ab_sort)):
        del(ab_sort[n])
    
print(pair)

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.sort(reverse=True)
CD.sort(reverse=True)

AB_set = []
CD_set = []
for index_ab, ab in enumerate(AB):
    i, j = -1, -1
    if index_ab in AB_set:
        continue
    distance = float('inf')
    for index_cd, cd in enumerate(CD):
        if index_cd in CD_set:
            continue
        if (cd[0] - ab[0] >= 0) & (cd[1] - ab[1] >= 0) & ((cd[0]-ab[0]) + (cd[1] - ab[1]) <= distance):
            distance = (cd[0] - ab[0]) + (cd[1] - ab[1])
            i, j = index_ab, index_cd
    if (i != -1) & (j != -1):
        AB_set.append(i)
        CD_set.append(j)

ans1 = len(AB_set)

AB.sort()
CD.sort()

AB_set = []
CD_set = []
for index_ab, ab in enumerate(AB):
    i, j = -1, -1
    if index_ab in AB_set:
        continue
    distance = float('inf')
    for index_cd, cd in enumerate(CD):
        if index_cd in CD_set:
            continue
        if (cd[0] - ab[0] >= 0) & (cd[1] - ab[1] >= 0) & ((cd[0]-ab[0]) + (cd[1] - ab[1]) <= distance):
            distance = (cd[0] - ab[0]) + (cd[1] - ab[1])
            i, j = index_ab, index_cd
    if (i != -1) & (j != -1):
        AB_set.append(i)
        CD_set.append(j)

ans2= len(AB_set)

print(max(ans1, ans2))

Submission status: Wrong Answer

Solution code:
red=[]
blue=[]
ans1=0
ans2=0

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


for i in red:
    for j in blue:
        if i[0]<j[0]:
            if i[1]<j[1]:
                ans1+=1
                blue.remove(j)
                break

for i in red:
    for j in blue:
        if i[1]<j[1]:
            if i[0]<j[0]:
                ans2+=1
                blue.remove(j)
                break

ans=max(ans1,ans2)
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)

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

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 red:
	d[i] = 0;
ans = 0;

for pr in blue:
	flag = 0;
	for x in range(pr[0]-1,-1,-1):

		for y in range(pr[1]-1,-1,-1):
			if d.get((x,y)) != None and d.get((x,y)) != 1:
				ans+=1;
				d[(x,y)] = 1;
				flag = 1;
				break;
		if flag == 1:
			break;

print ans;

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], reverse=True)
red_array2 = sorted(red_array, key=lambda x: x[1], 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], reverse=True)
blue_array2 = sorted(blue_array, key=lambda x: x[1], 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:
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=sorted(x,key=lambda x:x[0])
l=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
i=0
j=0
e=0
while(i<n and j<n):
	if(m[i][0]<p[j][0] and m[i][1]<p[j][1]):
		e+=1
		i+=1
		j+=1
	elif(m[i][0]>=p[j][0] or m[i][1]>=p[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]<o[j][0] and l[i][1]<o[j][1]):
		e+=1
		i+=1
		j+=1
	elif(l[i][0]>=o[j][0] or l[i][1]>=o[j][1]):
		j+=1
if(ma<e):
	ma=e
print(ma)

Submission status: Wrong Answer

Solution code:
n = int(input())
red_list = []
x_min = 200
for i in range(n):
    x, y = map(int, input().split())
    x_min = min(x_min, x)
    red_list.append((x, y))
red_list = sorted(red_list)
blue_list = []
for i in range(n):
    x, y = map(int, input().split())
    if x_min < x:
        blue_list.append((x, y))
blue_list = sorted(blue_list, key=lambda x: x[1])

max_pair = min(len(red_list), len(blue_list))
pair = 0
for blue in blue_list:
    for red in red_list:
        if blue[0] > red[0] and blue[1] > red[1]:
            pair += 1
            red_list.remove(red)
            break
    if pair >= max_pair:
        break

print(pair)

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


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 = int(input())
red = []
blue = []

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

red.sort()
blue.sort()
a_red = []
a_blue = []
ans = 0

for i in range(n):
    for j in range(n):
        if (blue[j][0] > red[i][0]) and (blue[j][1] > red[i][1]):
            blue[j] = [-1,-1]
            ans += 1
            break
    

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

Submission status: Wrong Answer

Solution code:
N = int(input())
pairs = 0

a = [list(map(int,input().split())) for i in range(N)]
b = [list(map(int,input().split())) for i in range(N)]
btree = [{} for i in range(N)]


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

for i in range(len(b)):
    for a_point in a:
        if small(a_point,b[i]):
            btree[i][str(a_point[0])+" "+str(a_point[1])] = 1
length = 0
min_len = 1
for bt in btree:
    length += len(bt)
k = 0
f_length = length
while length > 0:
    key = 0
    for i in range(N):
        if len(btree[i]) == min_len:
            key += 1
            pairs += 1
            ke = list(btree[i].keys())
            length -= (len(btree)-1)
            btree[i] = {}
            for i in range(N):
                if str(ke[0]) in btree[i]:
                    del btree[i][str(ke[0])]
                    length -= 1
            min_len = 1
            break
    if key <= 0:
        min_len += 1

if f_length ==0:
    print(0)
else:
    print(pairs)