Problem:


Score : 400 points

Problem Statement

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

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

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

Constraints

All input values are integers.

1 \leq N \leq 100

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

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

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

Input

Input is given from Standard Input in the following format:

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

Output

Print the maximum number of friendly pairs.

Sample Input 1

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

Sample Output 1

2

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

Sample Input 2

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

Sample Output 2

2

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

Sample Input 3

2
2 2
3 3
0 0
1 1

Sample Output 3

0

It is possible that no pair can be formed.

Sample Input 4

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

Sample Output 4

5

Sample Input 5

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

Sample Output 5

4



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


Sample output:
2

Submission status: Wrong Answer

Solution code:
N = int(input())
s = [0]*N
l = [0]*N
for i in range(N):
    a, b = map(int, input().split())
    s[i] = (a, b)
 
for i in range(N):
    c, d = map(int, input().split())
    l[i] = (c, d)




V = N*2 # 頂点数
MAX_V = V
G = [0]*MAX_V # グラフの隣接リスト表現
for i in range(MAX_V):
    G[i] = []
match = [0]*MAX_V # マッチングのペア
used = [False]*MAX_V # DFSで既に調べたかのフラグ

# uとvを結ぶ辺をグラフに追加する
def addEdge(u, v):
    G[u].append(v)
    G[v].append(u)

##
for a in range(N):
    (rx, ry) = s[a]
    for b in range(N):
        (bx, by) = l[b]
        if rx < bx and ry < by:
            addEdge(a, b+(N-1))


# 増加パスをDFSで探す
def dfs(v):
    used[v] = True
    for i in range(len(G[v])):
        u = G[v][i]
        w = match[u]
        if w < 0 or (not used[w]) and dfs(w):
            match[v] = u
            match[u] = v
            return True
    return False

# 二部グラフの最大マッチングを求める
def bipartiteMatching():
    res = 0
    for i in range(len(match)):
        match[i] = -1
    for v in range(V):
        if match[v] < 0:
            for i in range(len(used)):
                used[i] = False
            if dfs(v):
                res += 1
    return res


print(G)
print(match)
print(bipartiteMatching())

Submission status: Wrong Answer

Solution code:
n = int(input())

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

inf = 10**30

node = n*2+2

for i in range(1,n+1):
    ed.append([0,i,0])
    ed.append([n+i,2*n+1,0])
    
for i in range(n):
    for j in range(n):
        if red[i][0]<blue[j][0] and red[i][1]<blue[j][1]:
            ed.append([i+1,j+1,1])
    


edge = len(ed)
start = 0
goal = 2*n+1

"""
limit = [[0 for i in range(node)] for j in range(node)]
for i in edge:
    limit[i[0]][i[1]] += i[2]
"""

limit = [[] for i in range(node)]
for i in ed:
    limit[i[0]].append([i[1],i[2]])
    limit[i[1]].append([i[0],0])

ans = 0
while True:
    used = [False for i in range(node)]
    used[start] = True
    stack = [start]
    pre = [False for i in range(node)] # posの前
    pcos = [inf for i in range(node)] # posまでのコスト
    flg = False
    while stack:
        # print(stack)
        pos = stack.pop()
        for e in limit[pos]:
            if e[1] != 0 and (not used[e[0]]):
                pre[e[0]]=pos
                pcos[e[0]]=e[1]
                stack.append(e[0])
                used[e[0]]=True
                if e[0]==goal:
                    stack = []
                    flg = True
    if flg==False:
        print(ans)
        break
    pos = goal
    root = []
    minicost = inf
    while pos != start:
        root.append(pos)
        minicost = min(minicost,pcos[pos])
        pos = pre[pos]
    root.append(start)
    root.reverse()
    ans += minicost
    for i in range(len(root)-1):
        for j in range(len(limit[root[i]])):
            if limit[root[i]][j][0]==root[i+1]:
                limit[root[i]][j] = [root[i+1],limit[root[i]][j][1]-minicost]
        for j in range(len(limit[root[i+1]])):
            if limit[root[i+1]][j][0] == root[i]:
                limit[root[i+1]][j] = [root[i],limit[root[i+1]][j][1]+minicost]

Submission status: Wrong Answer

Solution code:

N = int(input())
s = [0]*N
l = [0]*N
for i in range(N):
    a, b = map(int, input().split())
    s[i] = (-a, -b)

for i in range(N):
    c, d = map(int, input().split())
    l[i] = (c, d)

s.sort()
l.sort()

ans = 0
dp = [True]*N
for e in s:
    a = -e[0]
    b = -e[1]

    ind = -1
    dist = int(1e18)
    for i in range(N):
        if dp[i]:
            c = l[i][0]
            d = l[i][1]
            
            if a < c and b < d:
                hoge = (c-a)*(c-a) + (d-b)*(d-b)
                if hoge < dist:
                    dist = hoge
                    ind = i
    if ind != -1:
        dp[ind] = False
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
from sys import exit, setrecursionlimit, stderr
from functools import reduce
from itertools import *
from collections import defaultdict
from bisect import bisect

def read():
  return int(input())

def reads():
  return [int(x) for x in input().split()]

N = read()
red = []
blue = []

for _ in range(N):
  a, b = reads()
  red.append((a, b))

for _ in range(N):
  c, d = reads()
  blue.append((c, d))

red.sort(); red.reverse()
blue.sort(); blue.reverse()

count = 0
for c, d in blue:
  try:
    p = next((a, b) for a, b in red if a < c and b < d)
    red.remove(p)
    count += 1
  except:
    pass

print(count)

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())

red_arr = np.zeros((N, 2))
blue_arr = np.zeros((N, 2))

for i in range(N):
    red_arr[i,:] = np.array(list(map(int, input().split())))

count = 0
for i in range(N):
    diff = np.array(list(map(int, input().split()))) - red_arr
    if (diff < 0).sum(axis = 1).prod() != 0:
        continue
    red_arr = np.delete(red_arr,\
            ((diff + (diff < 0) * 10**6).sum(axis = 1)).argmin(), 0)
    count += 1

print(count)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter

n = int(input())
lesser = [list(map(int, input().split())) for _ in range(n)]
greater = [list(map(int, input().split())) for _ in range(n)]

l1 = sorted(lesser, key=itemgetter(0))
g1 = sorted(greater, key=itemgetter(0))

ans1 = 0
for i in range(n):
	if l1[i][0] < g1[i][0] and l1[i][1] < g1[i][1]:
		ans1 += 1

l2 = sorted(lesser, key=itemgetter(1))
g2 = sorted(greater, key=itemgetter(1))

ans2 = 0
for i in range(n):
	if l2[i][0] < g2[i][0] and l2[i][1] < g2[i][1]:
		ans2 += 1

print(max(ans1, ans2))

Submission status: Wrong Answer

Solution code:
import math
import numpy as np
N = int(input())
a = np.zeros(N)
b = np.zeros(N)
c = np.zeros(N)
d = np.zeros(N)


for i in range(2*N):
    s = input().rstrip().split()
    A = int(s[0])
    B = int(s[1])
    if i < N:
        a[i] = A
        b[i]=B
    else:
        c[i - N] = A
        d[i - N] = B
dd=[]     
for i in range(N):
    aa = np.where(c > a[i])
    bb = np.where(d > b[i])
    cc = []
    
    for j in range(aa[0].shape[0]):
        num =  len(np.where(bb==aa[0][j])[0])
        if(num != 0):
            cc.append(aa[0][j])
    dd.append([cc,len(cc)])
dd.sort(key=lambda x: x[1])
x = 0
y=[]
for i in range(N):
    for j in range(dd[i][1]):
        if(dd[i][0][j] not in y):
            x += 1
            y.append(dd[i][0][j])
            break
print(x)

Submission status: Wrong Answer

Solution code:
N = int(input())
reds = [list(map(int, input().split())) for i in range(N)]
blues = [list(map(int, input().split())) for i in range(N)]
reds = sorted(list(enumerate(reds)), key= lambda x: x[1][0])
blues = sorted(list(enumerate(blues)), key=lambda x: x[1][1])
red_used = set()
blue_used = set()

for red in reds:
    for blue in blues:
        if red[0] in red_used or blue[0] in blue_used:
            continue
        if red[1][0] < blue[1][0] and red[1][1] < blue[1][1]:
            red_used.add(red[0])
            blue_used.add(blue[0])

print(len(blue_used))

Submission status: Wrong Answer

Solution code:
N = int(input())
reds = [list(map(int, input().split())) for i in range(N)]
blues = [list(map(int, input().split())) for i in range(N)]
reds = sorted(list(enumerate(reds)))
blues = sorted(list(enumerate(blues)), key=lambda x: x[1][1])
red_used = set()
blue_used = set()

for red in reds:
    for blue in blues:
        if red[0] in red_used or blue[0] in blue_used:
            continue
        if red[1][0] < blue[1][0] and red[1][1] < blue[1][1]:
            red_used.add(red[0])
            blue_used.add(blue[0])

print(len(blue_used))

Submission status: Wrong Answer

Solution code:
N = int(input())
reds = [list(map(int, input().split())) for i in range(N)]
blues = [list(map(int, input().split())) for i in range(N)]
reds = sorted(list(enumerate(reds)))
blues = sorted(list(enumerate(blues)), key=lambda x: x[1])
red_used = set()
blue_used = set()

for red in reds:
    for blue in blues:
        if red[0] in red_used or blue[0] in blue_used:
            continue
        if red[1][0] < blue[1][0] and red[1][1] < blue[1][1]:
            red_used.add(red[0])
            blue_used.add(blue[0])

print(len(blue_used))

Submission status: Wrong Answer

Solution code:
N = int(input())
ab = sorted([ tuple(map(int, input().split())) for x in range(N)])
cd = sorted([ tuple(map(int, input().split())) for x in range(N)], key=lambda x:x[1])
resultx = []
resulty = []
for xb, yb in list(cd):
    for xr, yr in list(ab):
        if (xr, yr) in resultx:
            continue
        if xr < xb and yr < yb:
            resultx.append((xr,yr))
            resulty.append((xb,yb))
            break

print(len(resultx))

Submission status: Wrong Answer

Solution code:
N = int(input())
ab = sorted([ tuple(map(int, input().split())) for x in range(N)])
cd = sorted([ tuple(map(int, input().split())) for x in range(N)], key=lambda xy: xy[1])
resultx = []
resulty = []
for xr, yr in list(ab):
    for xb, yb in list(cd):
        if (xb, yb) in resulty:
            continue
        if xr < xb and yr < yb:
            resultx.append((xr,yr))
            resulty.append((xb,yb))
            break

print(len(resultx))

Submission status: Wrong Answer

Solution code:
N = int(input())
ab = sorted([ tuple(map(int, input().split())) for x in range(N)])
cd = sorted([ tuple(map(int, input().split())) for x in range(N)], key=lambda xy: xy[1])
resultx = []
resulty = []
for xr, yr in list(ab):
    for xb, yb in list(cd):
        if xr < xb and yr < yb:
            if not (xb, yb) in resulty:
                resultx.append((xr,yr))
                resulty.append((xb,yb))
                break

print(len(resultx))

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)]
result = []
for i in range(N):
    xr , yr = ab[i]
    xb, yb = cd[i]
    if xr < xb or yr < yb:
        result.append('BINGO!!!')
print(len(result))

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)]
result = []
for i in range(N):
    xr , yr = ab[i]
    xb, yb = cd[i]
    if xr < xb and yr < yb:
        result.append('BINGO!!!')
print(len(result))

Submission status: Wrong Answer

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


R.sort(reverse=True)
B.sort()

p = []
for c, d in B:
    for a, b in R:
        if (a, b) in p:
            continue
        if a < c and b < d:
            p.append((a, b))
            break

print(len(p))

Submission status: Wrong Answer

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


def solve(i, p):
    if i == N:
        print(p)
        return len(p)

    s = []
    a, b = R[i]
    for c, d in B:
        if (c, d) in p:
            continue
        if a < c and b < d:
            # ペアになった
            s.append(solve(i+1, p + [(c, d)]))
    # ペアにならなかった
    s.append(solve(i+1, p))
    return max(s)


print(solve(0, []))

Submission status: Wrong Answer

Solution code:
import numpy as np

def check(r, b):
    return r[0] < b[0] and r[1] < b[1]

if __name__ == '__main__':
    N = int(input())
    RED = []
    BLUE = []
    flag = []
    for i in range(N):
        RED.append(list(map(int, input().split())))

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

    for r in RED:
        c_flag = []
        for b in BLUE:
            c_flag.append(check(r, b))
        flag.append(c_flag)

    flag = np.array(flag)
    args = np.argsort(np.sum(flag == True, axis=1))
    flag = flag[args]

    count = 0
    for i in range(N):
        arg = np.where(flag[i] == True)[0]
        if len(arg) is not 0:
            arg = arg[0]
            count += 1
            flag = np.delete(flag, arg, 1)
    print(count)

Submission status: Wrong Answer

Solution code:
def bigger(a, b):
    return a[0] > b[0] and a[1] > b[1]


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

ret = 0
ab_used, cd_used = [], []
for a in ab:
    for c in cd:
        if a in ab_used:
            break
        if c in cd_used:
            continue
        if bigger(c, a):
            ab_used.append(a)
            cd_used.append(c)
            ret += 1
            break

print(ret)

Submission status: Wrong Answer

Solution code:
def bigger(a, b):
    return a[0] > b[0] and a[1] > b[1]


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

ret = 0
ab_used, cd_used = [], []
for a in ab:
    for c in cd:
        if a in ab_used:
            break
        if c in cd_used:
            continue
        if bigger(c, a):
            ab_used.append(a)
            cd_used.append(c)
            ret += 1
            break

print(ret)

Submission status: Wrong Answer

Solution code:
def bigger(a, b):
    return a[0] > b[0] and a[1] > b[1]


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

ret = 0
ab_used, cd_used = [], []
for a in ab:
    for c in cd:
        if a in ab_used:
            break
        if c in cd_used:
            continue
        if bigger(c, a):
            ab_used.append(a)
            cd_used.append(c)
            ret += 1
            break

print(ret)

Submission status: Wrong Answer

Solution code:
import itertools
import threading
import time

res = 0


def add_and_xorer(a, b):
    global res
    res = res ^ (a + b)


n = int(input())
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))

res = 0

for a, b in itertools.product(a_list, b_list):
    th = threading.Thread(target=add_and_xorer, name="{}{}".format(a, b), args=(a, b,))
    th.start()

time.sleep(0.1)

print(res, flush=True)

Submission status: Wrong Answer

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

count = 0

for b in range(N):
    large = [-1 , -1]
    largeNum = None
    for r in range(N):
        if blue[b][0] >= red[r][0] and  blue[b][1] >= red[r][1]:
            if red[r][0] > large[0] and red[r][1] > large[1]:
                large = red[r]
                largeNum = r
    if not largeNum == None:
        red[largeNum] = [N ** 2 + 1, N ** 2 + 1]
        count += 1

print(count)

Submission status: Wrong Answer

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

count = 0

for b in range(N):
    large = [-1 , -1]
    largeNum = None
    for r in range(N):
        if blue[b][0] >= red[r][0] and  blue[b][1] >= red[r][1]:
            if red[r][0] > large[0] and red[r][1] > large[1]:
                large = red[r]
                largeNum = r
    if not largeNum == None:
        red[largeNum] = [N ** 2 + 1, N ** 2 + 1]
        count += 1

print(count)
print(red)

Submission status: Wrong Answer

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

count = 0

for b in range(N):
    large = [-1 , -1]
    largeNum = None
    for r in range(N):
        if blue[b][0] >= red[r][0] and  blue[b][1] >= red[r][1]:
            if red[r][0] > large[0] and red[r][1] > large[1]:
                large = red[r]
                largeNum = r
    if not largeNum == None:
        red[r] = [N ** 2 + 1, N ** 2 + 1]
        count += 1

print(count)

Submission status: Wrong Answer

Solution code:
class Atcoder:


    def Contest0901(self):
        lines = []
        for i in range(3):
            line = input()
            if line:
                lines.append(line)
            else:
                break
        return lines[0][0] + lines[1][1] + lines[2][2]

    def Contest092C(self):
        number = int(input())
        list = []
        num = 0
        for i in range(number):
            list.append(input())

        for j in range(number):
            temp = input()
            if temp[0] > list[j][0] and temp[2] > list[j][2]:
                num += 1
        return num
if __name__ == '__main__':
    atcoder = Atcoder()
    print(atcoder.Contest092C())

Submission status: Wrong Answer

Solution code:
import heapq

N = int(input())
red, blue, both = [], [], []
for _ in range(N):
    x, y = map(int, input().split())
    red.append((x, y))
    both.append((x, y, True))
for _ in range(N):
    x, y = map(int, input().split())
    blue.append((x, y))
    both.append((x, y, False))

# both.sort(key=lambda xyz: xyz[1])
both.sort(key=lambda xyz: xyz[0])

# According to the heapq documentation, the way to customize the heap order is
# to have each element on the heap to be a tuple, with the first tuple element
# being one that accepts normal Python comparisons.
red_heap = []
ans = 0
for xyz in both:
    if xyz[2]:
        y = xyz[1]
        heapq.heappush(red_heap, (-y, xyz))
    else:
        if not red_heap:
            continue
        heapq.heappop(red_heap)
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter

if __name__ == '__main__':
    N = int(input())
    plots = []
    for i in range(2 * N):
        x, y = map(int, input().split())
        if i < N:
            plots.append([x, y, "r"])
        else:
            plots.append([x, y, "b"])

    plots = sorted(plots, key=itemgetter(0))

    t_set = set()
    ans = 0
    for x, y, c in plots:
        if c == "r":
            t_set.add(y)
            continue

        if len(t_set) == 0 or y < min(t_set):
            continue

        ans += 1
        del_y = 0
        for tmp in t_set:
            if y > tmp > del_y:
                del_y = tmp

        t_set.remove(tmp)

    print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())

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

def nakayoshi(p1, p2):
    return int(all([ x1 < x2 for x1, x2 in zip(p1, p2) ]))

pair = [ [ nakayoshi(p1, p2) for p2 in blue ] for p1 in red ]

row = [ list(line) for line in np.array(pair).T ]
row.sort(key=lambda x:sum(x))

tmp = np.array([0 for i in range(N)])

count = 0

for i, line in enumerate(row):
    a = list(line - tmp)
    
    if 1 in a:
        count += 1
        tmp[i] = 1
    elif min(a) > 0:
        b = a.index(min(a))
        count += 1
        tmp[b] = 1

print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
abs_ = [tuple(map(int, input().split())) for _ in range(n)]
cds = [tuple(map(int, input().split())) for _ in range(n)]

ab_to = [set() for _ in range(len(abs_))]
cd_from = [set() for _ in range(len(cds))]

ab_pair = [-1 for _ in range(len(abs_))]
cd_pair = [-1 for _ in range(len(cds))]

def dfs(j, visited):
    i = cd_pair[j]
    if i == -1:
        return [j]
    visited.add(j)
    for k in ab_to[i]:
        if k in visited:
            continue
        #visited.add(k)
        r = dfs(k, visited)
        if r is not None:
            r.append(j)
            return r

for i, (a, b) in enumerate(abs_):
    for j, (c, d) in enumerate(cds):
        if a < c and b < d:
            ab_to[i].add(j)
            cd_from[j].add(i)
            if ab_pair[i] == -1 and cd_pair[j] == -1:
                ab_pair[i] = j
                cd_pair[j] = i

continue_ = True
while continue_:
    continue_ = False
    for i, (a, b) in enumerate(abs_):
        if ab_pair[i] == -1:
            visited = set()
            for cand in ab_to[i]:
                route = dfs(cand, visited)
                if route is not None:
                    continue_ = True
                    for k in range(len(route)-1):
                        a = cd_pair[route[k+1]]
                        ab_pair[a], cd_pair[route[k]] = route[k], a
                    ab_pair[i], cd_pair[route[-1]] = route[-1], i

print(sum(1 for p in ab_pair if p != -1))

Submission status: Wrong Answer

Solution code:
count = int(input())
a = [0]*count
b = [0]*count
c = 0
p = 0
m = 0
for i in range(count):
  a[i] = list(map(int,input().split()))
for j in range(count):
  b[j] = list(map(int,input().split()))
  
for k in range(count):
  if p == 1:
    break
  
  for l in range(m,count):
    if p == 1:
      break
    if a[k][0] < b[l][0]:
      if p == 1:
        break
      if a[k][1] < b[l][1]:
        if p == 1:
          break
        if l < count -1:
          m = l+1
        c += 1
        if l == count-1:
          p = 1
          break
        break
print(c)

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())

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

def nakayoshi(p1, p2):
    return int(all([ x1 < x2 for x1, x2 in zip(p1, p2) ]))

pair = [ [ nakayoshi(p1, p2) for p2 in blue ] for p1 in red ]

row = [ list(line) for line in np.array(pair).T ]
row.sort(key=lambda x:sum(x))

tmp = np.array([0 for i in range(N)])

count = 0

for i, line in enumerate(row):
    if 1 in line - tmp:
        count += 1
        tmp[i] = 1

print(count)

Submission status: Wrong Answer

Solution code:

N = int(input())
R = [list(map(int, input().split(' '))) + [list(), 0] for i in range(N)]
B = [list(map(int, input().split(' '))) + [list()] for i in range(N)]
R = sorted(R)
B = sorted(B)
for b in B:
    for r in R:
        if b[0] > r[0] and b[1] > r[1]:
            b[2].append(r)
            r[2].append(b)
B = sorted(B, key=lambda x:(len(x[2]), x[0], x[1]))
ans = 0
for b in B:
    rs = [r for r in b[2] if r[3] == 0]
    rs = sorted(rs, key=lambda x:(len(x[2]), x[0], x[1]))
    if len(rs) > 0:
        rs[0][3] += 1
        for r in rs:
            r[2].remove(b)
        ans += 1
# print(R)
# print(B)
print(ans)

Submission status: Wrong Answer

Solution code:
count = int(input())
a = [0]*count
b = [0]*count
c = 0
p = 0
m = 0
for i in range(count):
  a[i] = list(map(int,input().split()))
for j in range(count):
  b[j] = list(map(int,input().split()))
  
for k in range(count):
  if p == 1:
    break
  
  for l in range(m,count):
    if p == 1:
      break
    if a[k][0] < b[l][0]:
      if p == 1:
        break
      if a[k][1] < b[l][1]:
        if p == 1:
          break
        m = l+1
        c += 1
        if l == count-1:
          p = 1
          break
        break
print(c)

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())

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

def nakayoshi(p1, p2):
    return int(all([ x1 < x2 for x1, x2 in zip(p1, p2) ]))

pair = [ [ nakayoshi(p1, p2) for p2 in blue ] for p1 in red ]

row = [ list(line) for line in np.array(pair).T ]
row.sort(key=lambda x:sum(x))

tmp = np.array([0 for i in range(N)])

count = 0

for i, line in enumerate(row):
    if 1 in (line - tmp):
        # print(line - tmp)
        count += 1
    tmp[i] = 1

print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
a,b,c,d = [0]*N,[0]*N,[0]*N,[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())

e = [(0,"")]*2*N
f = [(0,"")]*2*N
for i in range(N):
    e[a[i]] = (b[i],"R")
    e[c[i]] = (d[i],"B")
    f[b[i]] = (a[i],"R")
    f[d[i]] = (b[i],"B")
    

ans1,p = 0,0
for i in range(2*N):
    n,c = e[i]
    if c == "R":
        p += 1
    else:
        p -= 1
        if p >= 0:
            ans1 += 1

ans2,p = 0,0
for i in range(2*N):
    n,c = f[i]
    if c == "R":
        p += 1
    else:
        p -= 1
        if p >= 0:
            ans2 += 1      

print(min(ans1,ans2))

Submission status: Wrong Answer

Solution code:
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
n=i1()
r=[]
b=[]
G=[[] for i in range(n*2+2)]

def add_edge(x,y,z):
  global G
  G[x].append( [y,z,len(G[y])]);
  G[y].append( [x,0,len(G[x])-1]);
used=[0 for i in range(n*2+2)]
def dfs(v,t,f):
	
	if (v==t):return f
	used[v] = 1
	for i in range(len(G[v])):
		e = G[v][i]
		if used[e[0]]==0 and e[1]>0:
			d = dfs(e[0], t, min(f,e[1]));
			if d > 0:
				e[1] -= d;
				
				G[e[0]][e[2]][1] += d
                                
				return d
			
		
	
	return 0


def max_flow(s,t):

	flow = 0
	while(1):
		used=[0 for i in range(n+2)]
		f = dfs(s, t, float("inf"))
		if f==0:
			return flow
		
		flow += f
	
for i in range(n):
 r.append(i2())
for i in range(n):
 b.append(i2())
for i in range(n):
 add_edge(0,i+1,1)
for i in range(n):
 add_edge(n+1+i,2*n+1,1)
for i in range(n):
 for j in range(n):
   if r[i][0]<b[j][0] or r[i][1]<b[j][1]:
       add_edge(1+i,n+1+j,1)
print(max_flow(0,2*n+1))

Submission status: Wrong Answer

Solution code:
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
n=i1()
r=[]
b=[]
G=[[] for i in range(n*2+2)]

def add_edge(x,y,z):
  global G
  G[x].append( [y,z,len(G[y])]);
  G[y].append( [x,0,len(G[x])-1]);
used=[0 for i in range(n*2+2)]
def dfs(v,t,f):
	
	if (v==t):return f
	used[v] = 1
	for i in range(len(G[v])):
		e = G[v][i]
		if used[e[0]]==0 and e[1]>0:
			d = dfs(e[0], t, min(f,e[1]));
			if d > 0:
				e[1] -= d;
				
				G[e[0]][e[2]][1] += d
                                
				return d
			
		
	
	return 0


def max_flow(s,t):

	flow = 0
	while(1):
		used=[0 for i in range(n+2)]
		f = dfs(s, t, float("inf"))
		if f==0:
			return flow
		
		flow += f
	
for i in range(n):
 r.append(i2())
for i in range(n):
 b.append(i2())
for i in range(n):
 add_edge(0,i+1,1)
for i in range(n):
 add_edge(n+1+i,2*n+1,1)
for i in range(n):
 for j in range(n):
   if r[i][0]<b[j][0] and r[i][1]<b[j][1]:
       add_edge(1+i,n+1+j,1)
print(max_flow(0,2*n+1))

Submission status: Wrong Answer

Solution code:
N = int(input())
a,b,c,d = [0]*N,[0]*N,[0]*N,[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())

e = [(0,"")]*2*N
for i in range(N):
    e[a[i]] = (b[i],"R")
    e[c[i]] = (d[i],"B")

ans,p = 0,0
for i in range(2*N):
    n,c = e[i]
    if c == "R":
        p += 1
    else:
        p -= 1
        if p >= 0:
            ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:

N = int(input())
R = [list(map(int, input().split(' '))) + [list(), 0] for i in range(N)]
B = [list(map(int, input().split(' '))) + [list()] for i in range(N)]
R = sorted(R)
B = sorted(B)
for b in B:
    for r in R:
        if b[0] > r[0] and b[1] > r[1]:
            b[2].append(r)
            r[2].append(b)
B = sorted(B, key=lambda x:len(x[2]))
ans = 0
for b in B:
    rs = [r for r in b[2] if r[3] == 0]
    rs = sorted(rs, key=lambda x:len(x[2]))
    if len(rs) > 0:
        rs[0][3] += 1
        for r in rs:
            r[2].remove(b)
        ans += 1
# print(R)
# print(B)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
a,b,c,d = [0]*N,[0]*N,[0]*N,[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())

e = [(0,"")]*2*N
for i in range(N):
    e[a[i]] = (b[i],"R")
    e[c[i]] = (d[i],"B")

ans,p = 0,0
for i in range(2*N):
    n,c = e[i]
    if c == "R":
        p += 1
        if p > 0:
            ans += 1
    else:
        p -= 1

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
ab = sorted(tuple(map(int, input().split())) for _ in range(n))
cd = sorted(tuple(map(int, input().split())) for _ in range(n))
for a, b in ab:
    i = -1
    y = 2*n
    for j, (c, d) in enumerate(cd):
        if a < c and b < d and d < y:
            i = j
            y = d
    if i != -1:
        del cd[i]
print(n - len(cd))

Submission status: Wrong Answer

Solution code:
N = int(input())
a,b,c,d = [0]*N,[0]*N,[0]*N,[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())

e = [(0,"")]*2*N
for i in range(N):
    e[a[i]] = (b[i],"R")
    e[c[i]] = (d[i],"B")

ans,p = 0,0
for i in range(2*N):
    n,c = e[i]
    if c == "R":
        p += 1
        if p > 0:
            ans += 1
    else:
        p -= 1

print(ans,e)