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: Accepted

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

R = sorted(R, key = lambda x: -1*x[1])
B = sorted(B)

ans = 0
for b in B:
    for r in R:
        if r[0] < b[0] and r[1] < b[1]:
            ans += 1
            R.remove(r)
            break

print(ans)

Submission status: Accepted

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]
    
    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:
            if not (red_point in pair) and not (blue_point in pair):
                pair.append(red_point)
                pair.append(blue_point)
    
print(len(pair) // 2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from operator import itemgetter

n = int(input())
red = []
blue = []
ans = 0
for i in range(n):
    red.append(list(map(int, input().split())))
for i in range(n):
    blue.append(list(map(int, input().split())))

# 青点を左から見ていって、その青点より左にありかつ一番上にある赤点をペアにしていく(貪欲)
# 青点からみて下にある赤点ほどペアとしての汎用性が高い
blue = sorted(blue, key=itemgetter(0))  # x座標で昇順
red = sorted(red, key=itemgetter(0))    # x座標で昇順

for b in blue:
    max_value = -1   # minは0
    for r in red:
        if b[0] <= r[0]:  # 青点より右に赤点が合った時点で終了
            break
        else:   # 青点より左側にある赤点の中からy値が最も大きいものを探す
            if max_value < r[1] and b[1] > r[1]:
                max_value = r[1]
                max_obj = r
    if max_value != -1: # ペア候補があれば
        ans += 1
        red.pop(red.index(max_obj))

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

print(count)

Submission status: Accepted

Solution code:
N=int(input())

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

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

ans = 0

for bluex, bluey in blue:
    for redx, redy in red:
        if bluex>redx and bluey>redy:
#            del red[red.index([redx,redy])]
            red.remove([redx,redy])
            ans+=1
            break

print(ans)

Submission status: Accepted

Solution code:
my_input = input

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

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

Submission status: Accepted

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

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


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

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

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

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

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

Submission status: Accepted

Solution code:
n = int(input())
red = [list(map(int, input().split())) for i in range(n)]
red.sort(key=lambda x:x[1], reverse=True)
blue = [list(map(int, input().split())) for i in range(n)]
blue = sorted(blue)
ans = 0
for x_b, y_b in blue:
  for x_r, y_r in red:
    if x_r < x_b and y_r < y_b:
      red.remove([x_r, y_r])
      ans += 1
      break
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
r = [[int(i) for i in input().split()] for _ in range(N)]
b = [[int(i) for i in input().split()] for _ in range(N)]

b1 = sorted(b)
r1 = sorted(r, key=lambda x: x[1])[::-1]

cnt = 0
for ib in b1:
    for ir in r1:
        if ir[0] < ib[0] and ir[1] < ib[1]:
            cnt += 1
            r1.remove(ir)
            break
print(cnt)

Submission status: Accepted

Solution code:
n=int(input())
red=[list(map(int,input().split()))for i in range(n)]
blue=[list(map(int,input().split()))for i in range(n)]
red.sort(reverse=True)#降順に並び替える
blue.sort(key=lambda x:x[1])#y座標を基準にソート
ans=0
for i in range(n):
    redx,redy=red[i][0],red[i][1]
    for j in range(len(blue)):
        bluex,bluey=blue[j][0],blue[j][1]
        if redx<bluex and redy<bluey:
            ans+=1
            blue.pop(j)
            break
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

R,B = sorted(R, key=lambda x: x[1])[::-1],sorted(B)

answer = 0
for i in B:
    for j in R:
        if i[0]>j[0] and i[1]>j[1]:
            answer += 1
            R.remove(j)
            break
print(answer)

Submission status: Accepted

Solution code:
N = int(input())
r = [[int(i) for i in input().split()] for i in range(N)]
b = [[int(i) for i in input().split()] for i in range(N)]
ans = 0
for p in r:
    p[0],p[1] = p[1], p[0]
r,b = sorted(r, reverse=True), sorted(b)
for i in b:
    for j in r:
        if i[0]>j[1] and i[1] >j[0]:
            ans += 1
            r.remove(j)
            break

print(ans)

Submission status: Accepted

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

for i in R:
    i[0],i[1] = i[1],i[0]
R,B = sorted(R)[::-1],sorted(B)

answer = 0
for i in B:
    for j in R:
        if i[0]>j[1] and i[1]>j[0]:
            answer += 1
            R.remove(j)
            break
print(answer)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

# AtCoder Beginner Contest 091
# C - 2D Plane 2N Points

from sys import stdin

def graph(red, blue):
    """
    Return the adjacent list of the bipartite graph that consists of
    the red vertices and the blue vertices.
    The red vertices are numbered as 0, 1, ..., N - 1 and
    the blue vertices are numbered as N, N + 1, ..., 2N - 1.
    The returned list contains 2N elements, each of which is
    the adjacent list of a vertex.
    """
    N = len(red)
    adj = [[] for i in range(2 * N)]
    for i in range(N):
        a, b = red[i]
        for j in range(N):
            c, d = blue[j]
            if a < c and b < d:
                adj[i]    .append(j + N)
                adj[j + N].append(i)
    return adj

def dfs(v, g, M, visited, path):
    if visited[v]: return None
    visited[v] = True
    for u in g[v]:
        w = M[u]
        if w == None: return path + [v, u]
        apath = dfs(w, g, M, visited, path + [v, u])
        if apath != None: return apath
    return None

def augPath(g, M):
    """
    For a graph g and a current matching M,
    return an augmenting path.
    If g does not have an augmenting path, then return None.
    """
    nvertices = len(g)
    for v in range(nvertices):
        if M[v] == None:
            visited = [False for v in range(nvertices)]
            apath = dfs(v, g, M, visited, [])
            if apath != None: return apath
    return None

def solve(red, blue):
    g = graph(red, blue)
    nvertices = len(g)
    # empty matching
    M = [None for v in range(nvertices)]
    # Find the maximum matching.
    while True:
        apath = augPath(g, M)
        if apath == None: break
        # Alter the matching.
        for i in range(0, len(apath), 2):
            v, u = apath[i : i + 2]
            M[v], M[u] = u, v
    nmatching = sum(1 for m in M if m != None) // 2
    return nmatching

def readIntPairList(N):
    """Read a list of N pairs of ints from stdin."""
    ls = []
    for i in range(N):
        a, b = [int(w) for w in stdin.readline().split()]
        ls.append((a, b))
    return ls

N = int(stdin.readline())
red  = readIntPairList(N)
blue = readIntPairList(N)
print(solve(red, blue))

Submission status: Accepted

Solution code:
n = int(input())
rc, bc = [], []

for i in range(n):
    rc.append(tuple(map(int, input().split())))

for i in range(n):
    bc.append(tuple(map(int, input().split())))

rc.sort(key=lambda tup: tup[0])
bc.sort(key=lambda tup: tup[0])

pairs = 0
for i in bc:
    pair = (200, -1)
    for j in rc:
        if i[0] < j[0]:
            break
        elif i[1] > j[1] > pair[1]:
            pair = j

    if i[0] > pair[0] and i[1] > pair[1]:
        pairs += 1
        rc.remove(pair)

print(pairs)

Submission status: Accepted

Solution code:
import bisect

def main():
    N = int(input())
    AB = [list(map(int, input().split())) for _ in [0] * N]
    CD = [list(map(int, input().split())) for _ in [0] * N]

    AB.sort()
    CD.sort()
    ab = list(map(list, zip(*AB)))
    ans = 0
    for c, d in CD:
        x = bisect.bisect_left(ab[0], c)
        if x:
            y = [(j, i) for i, j in enumerate(ab[1][:x]) if j < d]
            if y:
                maxy = max(y)
                ab[1][maxy[1]] = float('inf')
                ans += 1
    print(ans)

main()

Submission status: Accepted

Solution code:
n = int(input())
r = [[int(i) for i in input().split()] for i in range(n)]
b = [[int(i) for i in input().split()] for i in range(n)]

for i in r:
	i[0],i[1] = i[1],i[0]
r,b = sorted(r)[::-1],sorted(b)

answer = 0
for i in b:
	for j in r:
		if i[0]>j[1] and i[1]>j[0]:
			answer += 1
			r.remove(j)
			break
print(answer)

Submission status: Accepted

Solution code:
n = int(input())
reds = [list(int(_) for _ in input().split()) for i in range(n)]
blues = [list(int(_) for _ in input().split()) for i in range(n)]

reds.sort()
blues.sort()

cnt_pair = 0

for i in range(n):
  blue = blues[i]
  
  max_y = -1
  red_idx = -1
  
  for j in range(len(reds)):
    red = reds[j]
    
    if red[0] >= blue[0]:
      break
    
    if red[1] < blue[1] and red[1] > max_y:
      max_y = red[1]
      red_idx = j
    
  if red_idx >= 0:
    reds.pop(red_idx)
    cnt_pair += 1

print(cnt_pair)

Submission status: Accepted

Solution code:
n = int(input())

red = []
blue = []

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

red.sort(key=lambda x:x[1])
red.reverse()

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

res = 0

for b in range(n):
    for r in range(len(red)):
        if blue[b][0] > red[r][0] and blue[b][1] > red[r][1]:
            res += 1
            del red[r]
            break

print(res)

Submission status: Accepted

Solution code:
N = int(input())
a = [list(map(int, input().split())) for i in range(N)]
b = [list(map(int, input().split())) for i in range(N)]
a = sorted(a, key=lambda x: x[1])[::-1]
b = sorted(b)
ans = 0
for n in range(N):
    for i in range(len(b)):
        for j in range(len(a)):
            if b[i][0] > a[j][0]:
                if b[i][1] > a[j][1]:
                    ans+=1
                    del a[j]
                    del b[i]
                    break
        else:
            continue
        break
print(ans)

Submission status: Accepted

Solution code:
def sort_x(a):
    min = 100000
    min_num = 0
    n = len(a)
    A=[[0, 0] for i in range(n)]
    left_list = [1 for i in range(n)]

    for j in range(n):
        for i in range(n):
            if left_list[i]==1 and int(a[i][0]) < min:
                min = int(a[i][0])
                min_num = i
        left_list[min_num] = 0
        A[j] = a[min_num]
        min=100000
    return A

def sort_y(a):
    min = 100000
    min_num = 0
    n = len(a)
    A=[[0, 0] for i in range(n)]
    left_list = [1 for i in range(n)]

    for j in range(n):
        for i in range(n):
            if left_list[i]==1 and int(a[i][1]) < min:
                min = int(a[i][1])
                min_num = i
        left_list[min_num] = 0
        A[j] = a[min_num]
        min=100000
    return A

if __name__ == '__main__':
    n = int(input())
    a_ = [input().split() for i in range(n)]
    c_ = [input().split() for i in range(n)]
    a = [[0,0] for i in range(n)]
    c = [[0,0] for i in range(n)]
    c = sort_x(c_)
    a = sort_y(a_)
    
    frend_num = 0
    #print(a)
    #print(c)
    #min = 100000
    #min_index = 0
    filter_a = [1 for i in range(n)]
    for j in range(n):
        for i in reversed(range(n)):
            if filter_a[i]==1 and int(a[i][0])<int(c[j][0]) and int(a[i][1])<int(c[j][1]):
                        filter_a[i]=0
                        frend_num += 1
                        #print("{},{}".format(a,c))
                        #print("{}".format(filter_a))
                        #print("friend is detected")
                        break
    print(frend_num)

Submission status: Accepted

Solution code:
def sort_x(a):
    min = 100000
    min_num = 0
    n = len(a)
    A=[[0, 0] for i in range(n)]
    left_list = [1 for i in range(n)]

    for j in range(n):
        for i in range(n):
            if left_list[i]==1 and int(a[i][0]) < min:
                min = int(a[i][0])
                min_num = i
        left_list[min_num] = 0
        A[j] = a[min_num]
        min=100000
    return A

def sort_y(a):
    min = 100000
    min_num = 0
    n = len(a)
    A=[[0, 0] for i in range(n)]
    left_list = [1 for i in range(n)]

    for j in range(n):
        for i in range(n):
            if left_list[i]==1 and int(a[i][1]) < min:
                min = int(a[i][1])
                min_num = i
        left_list[min_num] = 0
        A[j] = a[min_num]
        min=100000
    return A

if __name__ == '__main__':
    n = int(input())
    a_ = [input().split() for i in range(n)]
    c_ = [input().split() for i in range(n)]
    a = [[0,0] for i in range(n)]
    c = [[0,0] for i in range(n)]
    c = sort_x(c_)
    a = sort_y(a_)
    
    frend_num = 0
    #print(a)
    #print(c)
    #min = 100000
    #min_index = 0
    filter_a = [1 for i in range(n)]
    for j in range(n):
        for i in reversed(range(n)):
            if filter_a[i]==1:
                if int(a[i][0])<int(c[j][0]) and int(a[i][1])<int(c[j][1]):
                        filter_a[i]=0
                        frend_num += 1
                        #print("{},{}".format(a,c))
                        #print("{}".format(filter_a))
                        #print("friend is detected")
                        break
    print(frend_num)

Submission status: Accepted

Solution code:
def sort_x(a):
    min = 100000
    min_num = 0
    n = len(a)
    A=[[0, 0] for i in range(n)]
    left_list = [1 for i in range(n)]

    for j in range(n):
        for i in range(n):
            if left_list[i]==1 and int(a[i][0]) < min:
                min = int(a[i][0])
                min_num = i
        left_list[min_num] = 0
        A[j] = a[min_num]
        min=100000
    return A

def sort_y(a):
    min = 100000
    min_num = 0
    n = len(a)
    A=[[0, 0] for i in range(n)]
    left_list = [1 for i in range(n)]

    for j in range(n):
        for i in range(n):
            if left_list[i]==1 and int(a[i][1]) < min:
                min = int(a[i][1])
                min_num = i
        left_list[min_num] = 0
        A[j] = a[min_num]
        min=100000
    return A

if __name__ == '__main__':
    n = int(input())
    a_ = [input().split() for i in range(n)]
    c_ = [input().split() for i in range(n)]
    a = [[0,0] for i in range(n)]
    c = [[0,0] for i in range(n)]
    c = sort_x(c_)
    a = sort_y(a_)
    
    frend_num = 0
    #print(a)
    #print(c)
    #min = 100000
    #min_index = 0
    filter_a = [1 for i in range(n)]
    for j in range(n):
        for i in reversed(range(n)):
            #print("---")
            #print("{} vs {}={}".format(a[i][0], c[j][0], a[i][0]<c[j][0]))
            #print("{} vs {}={}".format(a[i][1], c[j][1], a[i][1]<c[j][1]))
            if filter_a[i]==1:
                if int(a[i][0])<int(c[j][0]):
                    if int(a[i][1])<int(c[j][1]):
                        filter_a[i]=0
                        frend_num += 1
                        #print("{},{}".format(a,c))
                        #print("{}".format(filter_a))
                        #print("friend is detected")
                        break
    print(frend_num)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
s=[]
t=[]
for i in range(N):
    a,b=map(int,input().split())
    t+=[(a,b)]
for j in range(N):
    c,d=map(int,input().split())
    s+=[(c,d)]
s=sorted(s)
t=sorted(t)
for k in range(N):
    (x,y)=(-1,-1)
    for ii in range(len(t)):
        if s[k][0]>t[ii][0] and s[k][1]>t[ii][1] and y<t[ii][1]:
            (x,y)=t[ii]
    if (x,y) in t:        
        t.remove((x,y))
print(N-len(t))

Submission status: Accepted

Solution code:
N = int(input())
r = []
b = []
for i in range(N):
    r.append([int(i) for i in input().split()])

for i in range(N):
    b.append([int(i) for i in input().split()])

#print("r", r)
#print("b", b)

sorted_r = sorted(r, key=lambda r:r[1], reverse=True)
sorted_b = sorted(b)
#print("sorted_r", sorted_r)
#print("sorted_b", sorted_b)

ans = 0
for e1 in sorted_b:
    for e2 in sorted_r:
        if e2[0] < e1[0] and e2[1] < e1[1]:
            ans += 1
            sorted_r.remove(e2)
            break
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
red_list = []
blue_list = []

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

#2. search
#2.1 red:descending order in y
red_list.sort(key=lambda x:(x[1], x[0]), reverse=True)

#2.2 blue: ascending order
blue_list.sort(key=lambda x:(x[0], x[1]), reverse=False)

#2.3 search a blue point such as [x_r, y_r] < [x_b, y_b]
ans = 0
for red in red_list:
    for blue in blue_list:
        if (red[0]<blue[0]) and (red[1]<blue[1]):
            blue_list.remove(blue)
            ans += 1
            break

#3. print the result
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
r = [[int(i) for i in input().split()] for i in range(n)]
b = [[int(i) for i in input().split()] for i in range(n)]
for i in r:
	i[0],i[1] = i[1],i[0]
r,b = sorted(r)[::-1],sorted(b)
answer = 0
for i in b:
	for j in r:
		if i[0]>j[1] and i[1]>j[0]:
			answer += 1
			r.remove(j)
			break
print(answer)

Submission status: Accepted

Solution code:

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

Submission status: Accepted

Solution code:
from operator import itemgetter

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

blue=sorted(blue)  #青をxの小さい順にソート

red=sorted(red,key=itemgetter(1),reverse=True)

ans = 0

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

print(ans)

Submission status: Accepted

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

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

print(cnt)

Submission status: Accepted

Solution code:
# NG 15-

N = int(input())

R = []
for i in range(N):
    x, y = list(map(int, input().split()))
    R.append((x, y))

B = []
for i in range(N):
    x, y = list(map(int, input().split()))
    B.append((x, y))

R.sort(key=lambda a:a[1], reverse=True)
B.sort(key=lambda a:a[0], reverse=False)

ans = 0
for pos in B:
    x, y = pos
    for pos2 in R:
        x2, y2 = pos2
        if x2<x and y2<y:
            R.remove(pos2)
            ans += 1
            break

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
ans = 0
red = sorted([list(map(int, input().split())) for _ in range(n)], key=lambda x:-x[1])
blue = sorted([list(map(int, input().split())) for _ in range(n)])
for i in red:
    for num, j in enumerate(blue):
        if i[0] < j[0] and i[1] < j[1]:
            ans += 1
            del blue[num]
            break
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
ans = 0
red = sorted([list(map(int, input().split())) for _ in range(n)], key=lambda x:-x[1])
blue = sorted([list(map(int, input().split())) for _ in range(n)])
for i in red:
    for num, j in enumerate(blue):
        if i[0] < j[0] and i[1] < j[1]:
            ans += 1
            del blue[num]
            break
print(ans)

Submission status: Accepted

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

sortBlue = sorted(blue.items(), key=lambda x:x[0])
count = 0
for i in range(n):
	pair = {}
	for k, v in red.items():
		if (k < sortBlue[i][0]) and (v < sortBlue[i][1]):
			pair[k] = v
	if pair:
		sortPair = sorted(pair.items(), key=lambda x:-x[1])
		count += 1
		red.pop(sortPair[0][0])
		
print(count)

Submission status: Accepted

Solution code:
n = int(input())
red = sorted([list(map(int, input().split())) for _ in range(n)], key=lambda x:-x[1])
blue = sorted([list(map(int, input().split())) for _ in range(n)])
ans = 0
for b in blue:
    for i, r in enumerate(red):
        if r[0] < b[0] and r[1] < b[1]:
            ans += 1
            del red[i]
            break
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
ans = 0
red = sorted([list(map(int, input().split())) for _ in range(n)], key=lambda x:-x[1])
blue = sorted([list(map(int, input().split())) for _ in range(n)])
for i in red:
	for num, j in enumerate(blue):
		if i[0] < j[0] and i[1] < j[1]:
			ans += 1
			del blue[num]
			break
print(ans)

Submission status: Accepted

Solution code:
from operator import itemgetter
#入力
N = int(input())
red =[]
red_x = []
blue = []
blue_y = []
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])
#処理
#最もxの小さいblueとそいつで可能な最も大きいyをペアに
#blueをx座標昇順に
blue.sort(key = itemgetter(0))
#redをy座標降順に
red.sort(key = itemgetter(1),reverse = True)
count  = 0
for b in blue:
    for r in red:
        #可能なredを選び。降順になっているのでその中で最もyが大きいred
        if b[0]>=r[0] and b[1]>=r[1]:
                count +=1
                red.remove(r)
                break

print(count)

Submission status: Accepted

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

def solver1(N, reds, blues):
	""" 解説を実装
	青点のx座標が最も小さいものは、赤点のy座標の最も大きいものとペアになって良い
	"""
	sorted_reds  = sorted(reds, key=lambda x:x[1], reverse=True)  # y座標で降順ソート
	sorted_blues = sorted(blues, key=lambda x:x[0])  # x座標で昇順ソート
	ans = 0
	for i in range(N):
		for j in range(len(sorted_blues)):
			if (sorted_reds[i][0] < sorted_blues[j][0] and
			    sorted_reds[i][1] < sorted_blues[j][1]):
				ans += 1
				del sorted_blues[j]
				break
	print(ans)

if __name__ == "__main__":
	N = int(input())
	reds  = []
	blues = []
	for i in range(N):
		x, y = list(map(int, input().split()))
		reds.append([x, y])
	for i in range(N):
		x, y = list(map(int, input().split()))
		blues.append([x, y])

	solver1(N, reds, blues)

Submission status: Accepted

Solution code:
N = int(input())
ps = [tuple(map(int,input().split())) for i in range(2*N)]

es = [[] for i in range(2*N)]
for ri,(rx,ry) in enumerate(ps[:N]):
    for bi,(bx,by) in enumerate(ps[N:]):
        bi += N
        if rx < bx and ry < by:
            es[ri].append(bi)
            es[bi].append(ri)

used = [False] * (2*N)
match = [-1] * (2*N)

def _dfs(v):
    global used, match
    used[v] = True
    for u in es[v]:
        w = match[u]
        if w < 0 or not used[w] and _dfs(w):
            match[v] = u
            match[u] = v
            return True
    return False

def bipartite_matching():
    global used, match
    ret = 0
    for v in range(2*N):
        if match[v] < 0:
            used = [False] * (2*N)
            if _dfs(v):
                ret += 1
    return ret

print(bipartite_matching())

Submission status: Accepted

Solution code:
n = int(input())
ans = 0
red = sorted([ list(map(int,input().split())) for _ in range(n) ], key = lambda x : -x[1])
blue = sorted([ list(map(int,input().split())) for _ in range(n) ])
for i in red:
    for num,j in enumerate(blue):
        if i[0] < j[0] and i[1] < j[1]:
            ans += 1
            del blue[num]
            break
print(ans)

Submission status: Accepted

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 = sorted(Red, key=lambda x: -x[1])
Blue.sort()

res = 0
for i in range(N):
	for j in range(len(Blue)):
		if Red[i][0] < Blue[j][0] and Red[i][1] < Blue[j][1]:
			res += 1
			del Blue[j]
			break

print(res)

Submission status: Accepted

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

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

ans = 0
red = sorted(red, key=lambda tup: tup[1], reverse=True)
blue.sort()

for i in range(N):
    for j in range(len(blue)):
        if red[i][0] < blue[j][0] and red[i][1] < blue[j][1]:
            ans += 1
            del blue[j]
            break

print(ans)