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:
#!/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
    print(g)
    print(M)
    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: Wrong Answer

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)]
            return dfs(v, g, M, visited, [])
    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: Wrong Answer

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()
    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: Wrong Answer

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()
    ab = list(map(list, zip(*AB)))
    ans = 0
    for c, d in CD:
        x = bisect.bisect(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: Wrong Answer

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()
    ab = list(map(list, zip(*AB)))
    ans = 0
    for c, d in CD:
        x = bisect.bisect(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: Wrong Answer

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()
    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: Wrong Answer

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()
    ab = list(map(list, zip(*AB)))
    ans = 0
    for c, d in CD:
        x = bisect.bisect(ab[0], c)
        if not x:
            continue
        maxy = -1
        for y in ab[1][:x]:
            if y <= d:
                maxy = max(maxy, y)
        if maxy > -1:
            i = ab[1].index(maxy)
            ab[1][i] = float('inf')
            ans += 1
    print(ans)

main()

Submission status: Wrong Answer

Solution code:
def check_rec(bc, rc, pair):
    if len(bc) == 0 or len(rc) == 0:
        return pair

    bcc = bc.copy()
    e = bcc.pop()
    pairs = [pair]

    for i in rc:
        if e[0] > i[0] and e[1] > i[1]:
            rcc = rc.copy()
            rcc.remove(i)
            pairs.append(check_rec(bcc, rcc, pair+1))

    return max(pairs)


n = int(input())

rc, bc = set(), set()
for i in range(n):
    rc.add(tuple(map(int, input().split())))

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

print(check_rec(bc, rc, 0))

Submission status: Wrong Answer

Solution code:
import numpy as np
N=int(input())
a=[0 for i in range(N)];b=[0 for i in range(N)];c=[0 for i in range(N)];d=[0 for i in range(N)]
for i in range(N):a[i],b[i]=map(int,input().split())
for i in range(N):c[i],d[i]=map(int,input().split())
s=list(np.argsort(np.array(a)))
t=list(np.argsort(np.array(c)))
a=[a[s[i]] for i in range(N)];b=[b[s[i]] for i in range(N)]
c=[c[t[i]] for i in range(N)];d=[d[t[i]] for i in range(N)]
red=[0 for i in range(N)]
blue=[0 for i in range(N)]
answer=0
for i in range(N):
    T=[]
    for j in range(N):
        if a[j]<c[i]:
            if blue[j]==0:
                T.append(j)
        else:
            break
    if len(T)==0:continue
    l=0
    for k in T:
        if b[l]<=b[k]<d[i]:
            l=k
    blue[l]=1
    red[i]=1
    answer+=1
print(answer)

Submission status: Wrong Answer

Solution code:
N=int(input())
a=[0 for i in range(N)];b=[0 for i in range(N)];c=[0 for i in range(N)];d=[0 for i in range(N)]
for i in range(N):a[i],b[i]=map(int,input().split())
for i in range(N):c[i],d[i]=map(int,input().split())
for i in range(N):
    for j in range(i+1,N):
        if a[i]>a[j]:
            a[i],a[j]=a[j],a[i]
            b[i],b[j]=b[j],b[i]
        if c[i]>c[j]:
            c[i],c[j]=c[j],c[i]
            d[i],d[j]=d[j],d[i]
red=[0 for i in range(N)]
blue=[0 for i in range(N)]
answer=0
for i in range(N):
    T=[]
    for j in range(N):
        if a[j]<c[i]:
            if blue[j]==0:
                T.append(j)
        else:
            break
    if len(T)==0:continue
    l=0
    for k in T:
        if b[l]<=b[k]<d[i]:
            l=k
    blue[l]=1
    red[i]=1
    answer+=1
print(answer)

Submission status: Wrong Answer

Solution code:
n = int(input())

ab = []
cd = []

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

ab = sorted(ab)[::-1]
cd = sorted(cd)[::-1]

count = 0
for ab_ in ab:
    for cd_ in cd:
        if ab_[0] < cd_[0] and ab_[1] < cd_[1]:
            count += 1
            cd.remove(cd_)
            break
        #elif ab_[0] >= cd_[0]:
        #    cd.remove(cd_)
print(count)

Submission status: Wrong Answer

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])
blue.reverse()

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: Wrong Answer

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)[::-1]
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: Wrong Answer

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)[::-1]
b = sorted(b)[::-1]

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: Wrong Answer

Solution code:
def main():
    n = int(input())
    red = sorted(read_points(n))
    blue = sorted(read_points(n))

    ri = 0
    for bi in range(n):
        if red[ri] < blue[bi]:
            ri += 1

    print(ri)


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

    return ps


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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: Wrong Answer

Solution code:
import heapq


def get_next_int():
    return int(float(input()))


def get_next_ints(delim=" "):
    return tuple([int(float(x)) for x in input().split(delim)])


def get_next_str():
    return input()


def get_next_strs(delim=" "):
    return tuple(input().split(delim))


def get_next_by_types(*value_types, delim=" "):
    return tuple([t(x) for t, x in zip(value_types, input().split(delim))])


def solve():
    N = get_next_int()
    red_heap = []
    red_heap_rev = []
    for i in range(N):
        a, b = get_next_ints()
        heapq.heappush(red_heap, (b, a))
        heapq.heappush(red_heap_rev, (a, b))
    blue_heap = []
    blue_heap_rev = []
    for i in range(N):
        c, d = get_next_ints()
        heapq.heappush(blue_heap, (d, c))
        heapq.heappush(blue_heap_rev, (c, d))

    blue_heap = sorted(blue_heap)
    red_heap = sorted(red_heap)
    blue_heap_rev = sorted(blue_heap_rev)
    red_heap_rev = sorted(red_heap_rev)
    ans = 0
    while(len(blue_heap) > 0):
        blue_pos = heapq.heappop(blue_heap)
        for i in range(len(red_heap)):
            red_pos = red_heap[i]
            if blue_pos[0] > red_pos[0] and blue_pos[1] > red_pos[1]:
                ans += 1
                # heapq.heappop(red_heap)
                # print(blue_pos[1], blue_pos[0], red_pos[1], red_pos[0])
                del red_heap[i]
                break
            elif blue_pos[0] < red_pos[0]:
                break

    ans_rev = 0
    while(len(blue_heap_rev) > 0):
        blue_pos = heapq.heappop(blue_heap_rev)
        for i in range(len(red_heap_rev)):
            red_pos = red_heap_rev[i]
            if blue_pos[0] > red_pos[0] and blue_pos[1] > red_pos[1]:
                ans_rev += 1
                # heapq.heappop(red_heap_rev)
                # print(blue_pos[1], blue_pos[0], red_pos[1], red_pos[0])
                del red_heap_rev[i]
                break
            elif blue_pos[0] < red_pos[0]:
                break
    ans = max(ans, ans_rev)
    print(ans)


solve()

Submission status: Wrong Answer

Solution code:
import heapq


def get_next_int():
    return int(float(input()))


def get_next_ints(delim=" "):
    return tuple([int(float(x)) for x in input().split(delim)])


def get_next_str():
    return input()


def get_next_strs(delim=" "):
    return tuple(input().split(delim))


def get_next_by_types(*value_types, delim=" "):
    return tuple([t(x) for t, x in zip(value_types, input().split(delim))])

def solve():
    N = get_next_int()
    red_heap = []
    for i in range(N):
        a, b = get_next_ints()
        heapq.heappush(red_heap, (b, a))
    blue_heap = []
    for i in range(N):
        c, d = get_next_ints()
        heapq.heappush(blue_heap, (d, c))

    blue_heap = sorted(blue_heap)
    red_heap = sorted(red_heap)
    ans = 0
    while(len(blue_heap) > 0):
        blue_pos = heapq.heappop(blue_heap)
        for i in range(len(red_heap)):
            red_pos = red_heap[i]
            if blue_pos[0] > red_pos[0] and blue_pos[1] > red_pos[1]:
                ans += 1
                del red_heap[i]
                break
            elif blue_pos[0] < red_pos[0]:
                break
    print(ans)


solve()

Submission status: Wrong Answer

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)])
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: Wrong Answer

Solution code:
n = int(input())
ab = sorted([[int(a) for a in input().split()] for _ in range(n)], key=lambda x:x[1])
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: Wrong Answer

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)])
count = 0
for c in cd:
    for a in ab:
        if (a[0]<c[0]) and (a[1]<c[1]):
            count += 1
            ab.append(a)
            break
print(count)

Submission status: Wrong Answer

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)],reverse=True)
count = 0
for i in range(n):
    cd[i].append(0)
for i in range(n):
    for j in range(n):
        if (ab[i][0]<cd[j][0]) and (ab[i][1]<cd[j][1]) and (cd[j][2]==0):
            count += 1
            cd[j][2]=1
            break
print(count)

Submission status: Wrong Answer

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

    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 a[i][0]<c[j][0] and a[i][1]<c[j][1]:
                filter_a[i]=0
                frend_num += 1
                #print("{},{}".format(a,c))
                #print("{}".format(filter_a))
                break
    print(frend_num)

Submission status: Wrong Answer

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

    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 a[i][0]<c[j][0] and a[i][1]<c[j][1]:
                filter_a[i]=0
                frend_num += 1
                print("{},{}".format(a,c))
                print("{}".format(filter_a))
                break
    print(frend_num)

Submission status: Wrong Answer

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

    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(len(c)):
        for i in reversed(range(len(a))):
            #print("{},{}".format(a,c))
            if filter_a[i]==1  and a[i][0]<c[j][0] and a[i][1]<c[j][1]:
                filter_a[i]=0
                frend_num += 1
                #print("{},{}".format(filter_a, filter_c))
    print(frend_num)

Submission status: Wrong Answer

Solution code:
def sort_x(a):
    min = 100
    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=100
    return A

def sort_y(a):
    min = 100
    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=100
    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 = sort_y(a)
    c = sort_x(c)
    frend_num = 0
    
    min = 100
    min_index = 0
    filter_a = [1 for i in range(n)]
    filter_c = [1 for i in range(n)]
    for j in range(len(c)):
        for i in reversed(range(len(a))):
            #print("{},{}".format(a,c))
            if filter_a[i]==1 and filter_c[j]==1:
                if a[i][0]<c[j][0] and a[i][1]<c[j][1]:
                    filter_a[i]=0
                    filter_c[j]=0
                    frend_num += 1
                    #print("{},{}".format(filter_a, filter_c))
    print(frend_num)

Submission status: Wrong Answer

Solution code:
def sort_x(a):
    min = 100
    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=100
    return A

def sort_y(a):
    min = 100
    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=100
    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 = sort_y(a)
    c = sort_x(c)
    frend_num = 0
    
    min = 100
    min_index = 0
    filter_a = [1 for i in range(n)]
    filter_c = [1 for i in range(n)]
    for j in range(len(c)):
        #print("{},{}".format(filter_a, filter_c))    
        for i in reversed(range(len(a))):
            if filter_a[i]==1 and filter_c[j]==1:
                if a[i][0]<c[j][0] and a[i][1]<c[j][1]:
                    filter_a[i]=0
                    filter_c[j]=0
                    frend_num += 1
                    break
    print(frend_num)

Submission status: Wrong Answer

Solution code:
def connect_num(A, C):
    n = len(A)
    connect_num = [0 for i in range(n)]
    for i in range(n):
        for j in range(n):
            if A[i][0]<C[j][0] and A[i][1]<C[j][1]:
                connect_num[j] += 1
    return connect_num
if __name__ == '__main__':
    n = int(input())
    a = [input().split() for i in range(n)]
    c = [input().split() for i in range(n)]

    #a = sort_x(a)
    #c = sort_y(c)
    frend_num = 0
    
    min = 100
    min_index = 0
                
    for j in range(len(c)):
        connection = connect_num(a,c)
        #print(connection)
        for i in range(len(connection)):
            if connection[i]!=0:
                break
            if i == len(connection)-1:
                print(frend_num)
                exit()
            
        for i in range(len(connection)):
            if connection[i]<min and connection[i]!=0:
                min = connection[i]
                min_index = i
        for i in range(len(a)):
            if a[i][0]<c[min_index][0] and a[i][1]<c[min_index][1]:
                #print("[{},{}]".format(a[i], c[min_index]))
                del c[min_index]
                del a[i]
                del connection[min_index]
                frend_num += 1
                break
        min = 100
        min_index = 0
    print(frend_num)

Submission status: Wrong Answer

Solution code:
def sort_x(a):
    min = 100
    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=100
    return A

def sort_y(a):
    min = 100
    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=100
    return A
def connect_num(A, C):
    n = len(A)
    connect_num = [0 for i in range(n)]
    for i in range(n):
        for j in range(n):
            if A[i][0]<C[j][0] and A[i][1]<C[j][1]:
                connect_num[j] += 1
    return connect_num
if __name__ == '__main__':
    n = int(input())
    a = [input().split() for i in range(n)]
    c = [input().split() for i in range(n)]

    #A = sort_x(a)
    #C = sort_y(c)
    frend_num = 0
    
    min = 100
    min_index = 0
                
    for j in range(len(c)):
        connection = connect_num(a,c)        
        for i in range(len(connection)):
            if connection[i]<min and connection[i]!=0:
                min = connection[i]
                min_index = i
        for i in range(len(a)):
            if a[i][0]<c[min_index][0] and a[i][1]<c[min_index][1]:
                #print("[{},{}]".format(a[i], c[min_index]))
                del c[min_index]
                del a[i]
                del connection[min_index]
                frend_num += 1
                break
        min = 100
        min_index = 0
    print(frend_num)

Submission status: Wrong Answer

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

N = int(input())
r = [tuple(map(int, input().split())) for _ in range(N)]
b = [tuple(map(int, input().split())) for _ in range(N)]

for tp_b in sorted(b, key=lambda tp: tp[0] + tp[1]):
    min_dist = tp_b[0] + tp_b[1]
    min_tp = None
    for tp in [tp_r for tp_r in r if tp_r[0] < tp_b[0] and tp_r[1] < tp_b[1]]:
        tmp_dist = (tp_b[0] - tp[0]) + (tp_b[1] - tp[1])
        if tmp_dist <= min_dist:
            min_dist = tmp_dist
            min_tp = tp
    if min_tp is not None:
        r.remove(min_tp)

print(len(b) - len(r))