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:
lisx = []
lix = []
lisy = []
liy = []
n = int(input())
for i in range(n):
  a,b = map(int,input().split())
  lisx.append([a,b])
  lisy.append([b,a])
for i in range(n):
  a,b = map(int,input().split())
  lix.append([a,b])
  liy.append([b,a])
lisx.sort()
lix.sort()
lisy.sort()
liy.sort()
cou = 0
co = 0
for i in range(n):
  for j in range(len(lix)):
    if lisx[i][0] < lix[j][0] and lisx[i][1] < lix[j][1]:
      cou += 1
      del lix[j]
      break
for i in range(n):
  for j in range(len(liy)):
    if lisy[i][0] < liy[j][0] and lisy[i][1] < liy[j][1]:
      co += 1
      del liy[j]
      break
print(max(cou,co))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
A = []
B = []
C = []
D = []
N = int(input())
answer = N
for i in range(N) :
    a,b = map(int,input().split())
    A.append(a)
    B.append(b)
for j in range(N) :
    c,d = map(int,input().split())
    C.append(c)
    D.append(d)
A = list(reversed(A))
B = list(reversed(B))
C = list(reversed(C))
D = list(reversed(D))
for k in range(N) :
    if A[k] >= C[k] or B[k] >= D[k] :
        answer -= 1
    else :
        A[0] = B[0] = C[0] = D[0] = -1
print(answer)

Submission status: Wrong Answer

Solution code:
A = []
B = []
C = []
D = []
N = int(input())
answer = N
for i in range(N) :
    a,b = map(int,input().split())
    A.append(a)
    B.append(b)
for j in range(N) :
    c,d = map(int,input().split())
    C.append(c)
    D.append(d)
A = list(reversed(A))
B = list(reversed(B))
C = list(reversed(C))
D = list(reversed(D))
for k in range(N) :
    if A[k] >= C[k] or B[k] >= D[k] :
        answer -= 1
    else :
        A[k] = B[k] = C[k] = D[k] = -1
print(answer)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter
# N = 5
# R = [[0, 0],
#      [7, 3],
#      [2, 2],
#      [4, 8],
#      [1, 6]]

# B = [[8, 5], 
#      [6, 9], 
#      [5, 4], 
#      [9, 1],
#      [3, 7]]
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(key=itemgetter(0))
B.sort(key=itemgetter(0))
res = 0
for r in R:
    rx, ry = r[0], r[1]
    flag1 = False
    flag2 = False
    
    for i, b in enumerate(B):
        if b[0] > rx:
            flag1 = True
            break
    
    if flag1:
        B_tmp = B.copy()[i:]
        B_tmp.sort(key=itemgetter(1))
        for ii, b in enumerate(B_tmp):
            if b[1] > ry:
                flag2 = True
                break
        if flag2:
            res += 1
            B.remove(b)
print(res)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter
# N = 5
# R = [[0, 0],
#      [7, 3],
#      [2, 2],
#      [4, 8],
#      [1, 6]]

# B = [[8, 5], 
#      [6, 9], 
#      [5, 4], 
#      [9, 1],
#      [3, 7]]
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(key=itemgetter(0))
B.sort(key=itemgetter(0))
print(R)
print(B)
res = 0
for r in R:
    rx, ry = r[0], r[1]
    flag1 = False
    flag2 = False
    
    for i, b in enumerate(B):
        if b[0] > rx:
            flag1 = True
            break
    
    if flag1:
        B_tmp = B.copy()[i:]
        B_tmp.sort(key=itemgetter(1))
        for ii, b in enumerate(B_tmp):
            if b[1] > ry:
                flag2 = True
                break
        if flag2:
            res += 1
            B.remove(b)
print(res)

Submission status: Wrong Answer

Solution code:
import numpy as np

n = int(input())

red, blue = [], []
red_md, blue_md = [], []  # md: Manhattan Distance

for _ in range(n):
    b = list(map(int, input().split()))
    md = sum(b)
    blue.append(b)
    blue_md.append(md)

for _ in range(n):
    r = list(map(int, input().split()))
    md = sum(r)
    red.append(r)
    red_md.append(md)

# print(red)
# print(red_md)
# print(blue)

red_sorted_ind = np.argsort(red_md)
used = []
count = 0
# print(red_sorted_ind)

for ind in red_sorted_ind:
    pair = []
    # print("==== ind : {} ====".format(ind))
    for j, b in enumerate(blue):
        if j not in used:
            if (red[ind][0] > b[0]) & (red[ind][1] > b[1]):
                pair.append(j)

    # print(pair)

    if len(pair) == 1:
        count += 1
        used.append(pair[0])

    elif len(pair) > 1:
        max_md = 0
        best_j = 0
        for p in pair:
            md = blue_md[p]
            # print("p: {}, md: {}".format(p, md))
            if max_md < md:
                max_md = md
                best_j = p

        used.append(p)

print(len(used))

Submission status: Wrong Answer

Solution code:
from copy import copy

N = int(input())

XtoBR = {}
YtoBR = {}
Rnumber = {}
for i in range(N):
    a, b = map(int, input().split())

    Rnumber[i] = (a, b)
    XtoBR[a] = ("R", i)
    YtoBR[b] = ("R", i)

Bnumber = {}
for i in range(N):
    a, b = map(int, input().split())

    Bnumber[i] = (a, b)
    XtoBR[a] = ("B", i)
    YtoBR[b] = ("B", i)

X_list = sorted(list(XtoBR.keys()))

ClearX = {}
clear = set()

ans = 0
for x in reversed(X_list):
    if(XtoBR[x][0] == "B"):
        clear.add(XtoBR[x][1])
    else:
        ClearX[XtoBR[x][1]] = copy(clear)

Y_list = sorted(list(YtoBR.keys()))

clear = set()
for y in reversed(Y_list):
    if(YtoBR[y][0] == "B"):
        clear.add(YtoBR[y][1])
        continue

    n = YtoBR[y][1]
    allclear = clear & ClearX[n]
    # print(clear, ClearX[n], allclear)
    if(len(allclear) == 0):
        continue

    tmp = 2 * N + 1
    # print(allclear)
    for i in allclear:
        if(Bnumber[i][0] < tmp):
            tmp = i

    ans += 1
    clear.remove(tmp)

print(ans)

Submission status: Wrong Answer

Solution code:
from copy import copy

N = int(input())

XtoBR = {}
YtoBR = {}
Rnumber = {}
for i in range(N):
    a, b = map(int, input().split())

    Rnumber[i] = (a, b)
    XtoBR[a] = ("R", i)
    YtoBR[b] = ("R", i)

for i in range(N):
    a, b = map(int, input().split())

    XtoBR[a] = ("B", i)
    YtoBR[b] = ("B", i)

X_list = sorted(list(XtoBR.keys()))

ClearX = {}
clear = set()

ans = 0
for x in reversed(X_list):
    if(XtoBR[x][0] == "B"):
        clear.add(XtoBR[x][1])
    else:
        ClearX[XtoBR[x][1]] = copy(clear)

Y_list = sorted(list(YtoBR.keys()))

clear = set()
for y in reversed(Y_list):
    if(YtoBR[y][0] == "B"):
        clear.add(YtoBR[y][1])
        continue

    n = YtoBR[y][1]
    allclear = clear & ClearX[n]
    # print(clear, ClearX[n], allclear)
    if(len(allclear) == 0):
        continue

    tmp = -1
    # print(allclear)
    for i in allclear:
        if(Rnumber[i][0] > tmp):
            tmp = i

    ans += 1
    clear.remove(tmp)

print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a={tuple(map(int,input().split())):False for _ in range(n)}
b=sorted([tuple(map(int,input().split())) for _ in range(n)])[::-1]

ak=sorted(a.keys())[::-1]

for i in b:
  for j in ak:
    if i[0]<j[0] or i[1]<j[1] or a[j]:continue
    else:
      a[j]=True
      break

print(sum(a.values()))

Submission status: Wrong Answer

Solution code:
n = int(input())
A = [[int(i) for i in input().split()] for j in range(n)]
C = [[int(i) for i in input().split()] for j in range(n)]


ans = []

for bits in range(1, 2**4):
    cnt = 0
    used = [False] * n
    A.sort(key=lambda x:x[bits & 1], reverse=bits >> 1 & 1)
    C.sort(key=lambda x:x[bits >> 2 & 1], reverse=bits >> 3 & 1)

    for a, b in A:
        i = 0
        while i < n and (used[i] or a >= C[i][0] or b >= C[i][1]):
            i += 1
        if i >= n:
            break
        cnt += 1
        used[i] = True
        i += 1
        

    ans.append(cnt)

print(max(ans))

Submission status: Wrong Answer

Solution code:
n = int(input())
A = [[int(i) for i in input().split()] for j in range(n)]
C = [[int(i) for i in input().split()] for j in range(n)]


ans = []

for bits in range(1, 2**4):
    i = 0
    cnt = 0
    A.sort(key=lambda x:x[bits & 1], reverse=bits >> 1 & 1)
    C.sort(key=lambda x:x[bits >> 2 & 1], reverse=bits >> 3 & 1)

    for a, b in A:
        while i < n and (a >= C[i][0] or b >= C[i][1]):
            i += 1
        if i >= n:
            break
        cnt += 1
        i += 1
        

    ans.append(cnt)

print(max(ans))

Submission status: Wrong Answer

Solution code:
n = int(input())
A = [[int(i) for i in input().split()] for j in range(n)]
C = [[int(i) for i in input().split()] for j in range(n)]


ans = []

for bits in range(1, 2**4):
    i = 0
    cnt = 0
    A.sort(key=lambda x:x[bits & 1], reverse=bits >> 1 & 1)
    C.sort(key=lambda x:x[bits >> 2 & 1], reverse=bits >> 3 & 1)

    for a, b in A:
        if a < C[i][0] and b < C[i][1]:
            cnt += 1
        i += 1
        if i >= n:
            break

    ans.append(cnt)

print(max(ans))

Submission status: Wrong Answer

Solution code:

# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from pprint import pprint
from collections import Counter, defaultdict, deque
import queue
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


def Prim(g):
    V = list(g.keys())
    for v in g.values():
        V.extend(list(v.keys()))
    V = list(set(V))

    used = set([])
    q = []
    heapq.heappush(q, (0, V[0]))

    ret = 0
    while q:
        c, v = heapq.heappop(q)

        if v in used:
            continue
        used.add(v)
        ret += c
        for u in g[v]:
            heapq.heappush(q, (g[v][u], u))
    return ret


class Dinic:
    def __init__(self, v, inf=sys.maxsize):
        self.V = v
        self.inf = inf
        self.G = [[] for _ in range(v)]
        self.level = [0 for _ in range(v)]
        self.iter = [0 for _ in range(v)]

    def add_edge(self, from_, to, cap):
        # to: 行き先, cap: 容量, rev: 反対側の辺
        self.G[from_].append({'to': to, 'cap': cap, 'rev': len(self.G[to])})
        self.G[to].append({'to': from_, 'cap': 0, 'rev': len(self.G[from_])-1})

    # sからの最短距離をbfsで計算
    def bfs(self, s):
        self.level = [-1 for _ in range(self.V)]
        self.level[s] = 0
        que = queue.Queue()
        que.put(s)
        while not que.empty():
            v = que.get()
            for i in range(len(self.G[v])):
                e = self.G[v][i]
                if e['cap'] > 0 and self.level[e['to']] < 0:
                    self.level[e['to']] = self.level[v] + 1
                    que.put(e['to'])

    # 増加バスをdfsで探す
    def dfs(self, v, t, f):
        if v == t:
            return f
        for i in range(self.iter[v], len(self.G[v])):
            self.iter[v] = i
            e = self.G[v][i]
            if e['cap'] > 0 and self.level[v] < self.level[e['to']]:
                d = self.dfs(e['to'], t, min(f, e['cap']))
                if d > 0:
                    e['cap'] -= d
                    self.G[e['to']][e['rev']]['cap'] += d
                    return d

        return 0

    def max_flow(self, s, t):
        flow = 0
        while True:
            self.bfs(s)
            # bfsで到達不可
            if self.level[t] < 0:
                return flow
            self.iter = [0 for _ in range(self.V)]
            f = self.dfs(s, t, self.inf)
            while f > 0:
                flow += f
                f = self.dfs(s, t, self.inf)


@mt
def slv(N, AB, CD):
    cd_ = [(i+1, x, y) for i, (x, y) in enumerate(CD)]
    cd_x = sorted(cd_, key=lambda x: x[1])
    cd_x_keys = [x[1] for x in cd_x]
    cd_y = sorted(cd_, key=lambda x: x[2])
    cd_y_keys = [y[2] for y in cd_y]

    d = Dinic(2*N+2)
    for i in range(1, N+1):
        d.add_edge(0, i, 1)
        d.add_edge(i+N, 2*N+1, 1)
    for i, (x, y) in enumerate(AB):
        ix = bisect.bisect_left(cd_x_keys, x)
        iy = bisect.bisect_left(cd_y_keys, y)
        e = set([j for j, x, y in cd_x[ix:]]) | set(
            [j for j, x, y in cd_y[iy:]])
        # print("-------")
        for j in e:
            # print(i, j)
            d.add_edge(i, j+N, 1)

    return d.max_flow(0, 2*N+1)


def main():
    N = read_int()
    AB = [read_int_n() for _ in range(N)]
    CD = [read_int_n() for _ in range(N)]

    print(slv(N, AB, CD))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
a = []
c = []
for i in range(n):
    x1,y1=[int(i) for i in input().split()]
    a.append([x1,y1])
for i in range(n):
    x1,y1=[int(i) for i in input().split()]
    c.append([x1,y1])
a = sorted(a,key=lambda x:-x[0])
c = sorted(c,key=lambda x:-x[0])
aa = sorted(a,key=lambda x:-x[1])
cc = sorted(c,key=lambda x:-x[1])
ans = 0
for i in range(n):
  e = c[i]
  for j in range(len(a)):
    if (e[0] > a[j][0] and e[1] > a[j][1]):
      a.pop(j)
      ans += 1
      break
ans2 = 0
for i in range(n):
  e = cc[i]
  for j in range(len(aa)):
    if (e[0] > aa[j][0] and e[1] > aa[j][1]):
      aa.pop(j)
      ans2 += 1
      break
print(max(ans,ans2))

Submission status: Wrong Answer

Solution code:
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(10000)


# Debug output
def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))


# Binary converter
def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]


# --------------------------------------------

dp = None


def is_inside_and_short(r, b, minb):
    c1 = r[0] < b[0] and r[1] < b[1]
    c2 = math.sqrt((b[0]**2) +
                   (b[1]**2)) < math.sqrt((minb[0]**2) + minb[1]**2)

    return c1 and c2


def is_inside_and_minx(r, b, minb):
    c1 = r[0] < b[0] and r[1] < b[1]
    c2 = b[0] < minb[0]

    return c1 and c2


def is_inside_and_miny(r, b, minb):
    c1 = r[0] < b[0] and r[1] < b[1]
    c2 = b[1] < minb[1]

    return c1 and c2


def is_inside_and_minxy(r, b, minb):
    c1 = r[0] < b[0] and r[1] < b[1]
    c2 = b[0] < minb[0] and b[1] < minb[1]

    return c1 and c2


def count(R, B, is_func):
    ans = 0
    Btmp = [x[:] for x in B]

    for r in R:
        minb = [999, 999]
        is_find = False

        for b in Btmp:
            if is_func(r, b, minb):
                minb = b
                is_find = True

        if is_find:
            ans += 1
            Btmp.remove(minb)

    return ans


def main():
    N = int(input())
    R = [li_input() for _ in range(N)]
    B = [li_input() for _ in range(N)]

    maxpair = 0

    # Rを原点からの距離順に並べ替える
    Rsort_dist = sorted(R, key=lambda r: math.sqrt((r[0]**2) + (r[1]**2)))

    # Rをx座標順に並べ替える
    Rsort_x = sorted(R, key=lambda r: r[0])

    # Rをy座標順に並べ替える
    Rsort_y = sorted(R, key=lambda r: r[1])

    for is_func in [
            is_inside_and_short, is_inside_and_minx, is_inside_and_miny,
            is_inside_and_minxy
    ]:
        maxpair = max(
            count(Rsort_dist, B, is_func),
            count(Rsort_x, B, is_func),
            count(Rsort_y, B, is_func),
        )

    print(maxpair)


main()

Submission status: Wrong Answer

Solution code:
N = int(input())
R = [list(map(int,input().split())) for i in range(N)]
B = [list(map(int,input().split())) for i in range(N)]
R.sort(key = lambda x:x[1], reverse=False)
B.sort(key = lambda x:x[0], reverse=False)
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: Wrong Answer

Solution code:
N = int(input())
A = [[int(i) for i in reversed(input().split())] for n in range(N)]
B = [[int(i) for i in input().split()] for n in range(N)]
A.sort(); A.reverse(); B.sort()
C = 0
i = 0
for b in B:
  found = False
  while not found:
    a = A[i]
    if a[1] < b[0] and a[0] < b[1]:
      found = True
      C += 1
      A.pop(i)
      i = 0
    elif i+1 == len(A):
      found = True
      i = 0
    else:
      i += 1
    print(a,b,found,C)
print(C)

Submission status: Wrong Answer

Solution code:
N=int(input())
red=[list(map(int, input().split())) for _ in range(N)]
blue=[list(map(int, input().split())) for _ in range(N)]
red.sort(key=lambda x:x[0])
blue.sort(key=lambda x:x[0])
ct=0
for j in reversed(red):
    for i in blue:
        if i[0]>j[0] and i[1]>j[1]:
            red.remove(j)
            blue.remove(i)
            ct+=1
            break
print(ct)

Submission status: Wrong Answer

Solution code:
n = int(input())
ab = [tuple(map(int, input().split(" "))) for i in range(n)]
cd = [tuple(map(int, input().split(" "))) for i in range(n)]

cd = sorted(cd, key=lambda x: min(x))

pair_count = 0
for cd_i in cd:
	can_ball_count = 0
	for ab_i in ab:
		if ab_i[0] < cd_i[0] and ab_i[1] < cd_i[1]:
			can_ball_count += 1
	if 1 <= can_ball_count-pair_count:
		pair_count += 1

print(pair_count)

Submission status: Wrong Answer

Solution code:
n = int(input())
ab = [tuple(map(int, input().split(" "))) for i in range(n)]
cd = [tuple(map(int, input().split(" "))) for i in range(n)]

pair_count = 0
for cd_i in cd:
	can_ball_count = 0
	for ab_i in ab:
		if ab_i[0] < cd_i[0] and ab_i[1] < cd_i[1]:
			can_ball_count += 1
		else:
			break
	if 1 <= can_ball_count-pair_count:
		pair_count += 1

print(pair_count)

Submission status: Wrong Answer

Solution code:
N=int(input())
l=[list(map(int,input().split())) for _ in range(N)]
m=[list(map(int,input().split())) for _ in range(N)]
o=[[i for (i,j) in enumerate(m) if j[0]>k[0] and j[1]>k[1]] for k in l]
s=set()
for i in sorted(o,key=lambda x:len(x)):
  for l in i:
    if not l in s:
      s.add(l)
      break
print(len(s))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = []
c = []

for i in range(n):
    a.append([int(i) for i in input().split()])
for i in range(n):
    c.append([int(i) for i in input().split()])

a = sorted(a)
c = sorted(c)

count = 0
while len(a) > 0:
    ta, tb = a.pop()
    i = len(c) - 1
    while i > 0:
        tc, td = c[i]
        if ta < tc and tb < td:
            count += 1
            c.pop(i)
            break
        i -= 1

print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = []
c = []

for i in range(n):
    a.append([int(i) for i in input().split()])
for i in range(n):
    c.append([int(i) for i in input().split()])

a = sorted(a)
c = sorted(c)

count = 0
while len(a) > 0:
    ta, tb = a.pop()
    i = len(c) - 1
    while i > 0:
        tc, td = c[i]
        print(ta, tb, tc, td)
        if ta < tc and tb < td:
            count += 1
            c.pop(i)
            break
        i -= 1

print(count)

Submission status: Wrong Answer

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

red_coodinates.sort(reverse=True)
blue_coodinates.sort()
number_of_pairs=0

for i in range(N):
    for j in range(0,len(red_coodinates)):
        if red_coodinates[j][0]<blue_coodinates[i][0] and red_coodinates[j][1]<blue_coodinates[i][1]:
            number_of_pairs+=1
            red_coodinates.remove(red_coodinates[j])
            break
        else:
            pass

print(number_of_pairs)

Submission status: Wrong Answer

Solution code:
N = int(input())
red_points  = sorted([list(map(int, input().split())) for i in range(N)])
blue_points = sorted([list(map(int, input().split())) for i in range(N)],key = lambda x: (x[1], x[0]))
for blue_point in blue_points:
    blue_point.append(False)

ans = 0
for red_point in red_points:
    for blue_point in blue_points:
        if red_point[0] < blue_point[0] and red_point[1] < blue_point[1] and not blue_point[2]:
            ans += 1
            blue_point[2] = True
            break
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = [0] * N
b = [0] * N
c = [0] * N
d = [0] * 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(" "))
count = 0
while N > 0:
    idx = c.index(min(c))
    temp = []
    for j in range(N):
        if a[j] < c[idx]:
            if b[j] < d[idx]:
                temp.append(b[j])
    if temp:
        count += 1
        idx_ = b.index(max(temp))
        del a[idx_]
        del b[idx_]
    
    del c[idx]
    del d[idx]
    N -= 1
print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())

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

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

ans = 0

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

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

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


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

ans = 0
already_paired = []
for i in range(n):
    b = blue[i]
    current_diff = float('inf')
    found = 0
    minmum_index = False

    for k in range(n):
        r = red[k]

        if b[0] <= r[0]:
            break

        if b[1] <= r[1]:
            continue

        diff = b[1] - r[1]
        if (diff < current_diff) and (k not in already_paired):
            found = 1
            current_diff = diff
            minmum_index = k

    already_paired.append(minmum_index)
    ans += found


print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

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


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

print(red)
print(blue)

ans = 0
already_paired = []
for i in range(n):
    b = blue[i]
    current_diff = float('inf')
    found = 0
    minmum_index = False

    for k in range(n):
        r = red[k]

        if b[0] <= r[0]:
            break

        if b[1] <= r[1]:
            continue

        diff = b[1] - r[1]
        if (diff < current_diff) and (k not in already_paired):
            found = 1
            current_diff = diff
            minmum_index = k

    already_paired.append(minmum_index)
    ans += found


print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

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


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


ans = 0
already_paired = []
for i in range(n):
    b = blue[i]
    current_diff = float('inf')
    found = 0
    minmum_index = False

    for k in range(n):
        r = red[k]

        if b[0] <= r[0]:
            break

        if b[1] <= r[1]:
            continue

        diff = b[1] - r[1]
        if diff < current_diff and k not in already_paired:
            found = 1
            current_diff = diff
            minmum_index = k

    already_paired.append(minmum_index)
    ans += found


print(ans)

Submission status: Wrong Answer

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)]
l = [0] * N
def c(a,b):
    if a[0] < b[0] or a[1] < b[1]:return True
    return False
for r in red:
    m = 10000000
    mi = -1
    for i, b in enumerate(blue):
        if l[i]: continue
        if not c(r, b):continue
        tmp = sum([(a-b2)**2 for a,b2 in zip(r, b)])
        if m > tmp:
            mi = i
            m = tmp
    if mi != -1:
        l[mi] = 1
print(sum(l))

Submission status: Wrong Answer

Solution code:
N = int(input())

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

RedConnect = [set() for _ in range(N)]
BlueConnect = [set() for _ in range(N)]
for i, a in enumerate(Red):
    for j, b in enumerate(Blue):
        if a[0] < b[0] and a[1] < b[1]:
            RedConnect[i].add(j)
            BlueConnect[j].add(i)

res = 0
already = set()
alreadyB = set()
for i in range(N):
    if i in already:
        continue
    conn = RedConnect[i]
    already.add(i)
    countR = 1
    countB = 0
    while True:
        nextConn = set()
        for j in conn:
            nextConn = nextConn | BlueConnect[j]
        nextConn = nextConn - already
        countB += len(conn)
        alreadyB = alreadyB | conn
        
        conn2 = set()
        for a in nextConn:
            if a in already:
                continue
            conn2 = conn2 | RedConnect[a]
        conn2 = conn2 - alreadyB
        
        countR += len(nextConn)
        already = already | nextConn
        if len(conn2) == 0:
            break
        conn = conn2
    res += min(countR, countB)

print(res)

Submission status: Wrong Answer

Solution code:
n = int(input())
s, t = [], []
for i in range(n):
  a, b = list(map(int, input().split()))
  s.append((a+b, a, b))
for i in range(n):
  c, d = list(map(int, input().split()))
  t.append((c+d, c, d))
s.sort()
t.sort()

ans = 0
for i in range(n-1, -1, -1):
  for j in range(n-1, -1, -1):
    if t[j]==None:
      continue
    if s[i][1]<t[j][1] and s[i][2]<t[j][2]:
      ans+=1
      t[j] = None
      break
print(ans)

Submission status: Wrong Answer

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

# 青い点を探して処理する関数
def search_bluedot(end_x, end_y):
	# 更新する値をグローバル宣言
	global ans
	global field
	# Y軸向きには値の大きい方から優先して取るために、逆順でループ回す
	for y in range(end_y-1, -1, -1):
		for x in range(end_x):
			# 赤い点を見つけたら、答えを+1して赤い点を消す
			if field[y][x] == 1:
				ans += 1
				field[y][x] = 0
				return

dot_count = int(input())
# 点を置くフィールドを作成
field = [[0 for i in range(dot_count*2)] for j in range(dot_count*2)]
# 赤い点の配置
for i in range(dot_count):
	x, y = map(int, input().split())
	field[y][x] = 1
# 青い点の配置
for i in range(dot_count):
	x, y = map(int, input().split())
	field[y][x] = 2

ans = 0
for y in range(dot_count*2):
	for x in range(dot_count*2):
		# 青い点を見つけたら、そこより内側で赤い点を探す
		if field[y][x] == 2:
			search_bluedot(x, y)

print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())

ab=[]
cd=[]

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

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

ab.sort()
cd.sort()

#ab.reverse()
#cd.reverse()

ans=0

for i in range(N):
    L=len(cd)
    mi=1000000
    num=-1
    for j in range(L):
        if ab[i][1]<cd[j][1] and ab[i][2]<cd[j][2]:
            tmp=abs(ab[i][2]-cd[j][2])
            if tmp<mi:
                mi=tmp
                num=j
    if not num<0:
        del cd[num]
        ans+=1


print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())

ab=[]
cd=[]

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

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

ab.sort()
cd.sort()


ans=0

for i in range(N):
    L=len(cd)
    mi=1000000
    num=-1
    for j in range(L):
        if ab[i][1]<cd[j][1] and ab[i][2]<cd[j][2]:
            tmp=abs(ab[i][1]-cd[j][1])+abs(ab[i][2]-cd[j][2])
            if tmp<mi:
                mi=tmp
                num=j
    if not num<0:
        del cd[num]
        ans+=1


print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())

ab=[]
cd=[]

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

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

ab.sort()
cd.sort()

ab.reverse()
cd.reverse()

ans=0

for i in range(N):
    L=len(cd)
    mi=1000000
    num=-1
    for j in range(L):
        if ab[i][1]<cd[j][1] and ab[i][2]<cd[j][2]:
            tmp=abs(ab[i][1]-cd[j][1])+abs(ab[i][2]-cd[j][2])
            if tmp<mi:
                mi=tmp
                num=j
    if not num<0:
        del cd[num]
        ans+=1


print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())

ab=[]
cd=[]

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

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

ab.sort()
cd.sort()

ab.reverse()
cd.reverse()

ans=0

for i in range(N):
    L=len(cd)
    mi=1000000
    num=-1
    for j in range(L):
        if ab[i][0]<cd[j][0] and ab[i][1]<cd[j][1]:
            tmp=abs(ab[i][0]-cd[j][0])+abs(ab[i][1]-cd[j][1])
            if tmp<mi:
                mi=tmp
                num=j
    if not num<0:
        del cd[num]
        ans+=1


print(ans)