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())
Red = dict()
Redyset = set()
for _ in range(N):
    a,b = map(int,input().split())
    Red[b] = a
    Redyset.add(b)
Blue = dict()
Bluexset = set()
for _ in range(N):
    c,d = map(int,input().split())
    Blue[c] = d
    Bluexset.add(c)
Ans = 0
for i in range(N):
    Blx = min(Bluexset)
    Bluexset.remove(Blx)
    Bly = Blue.pop(Blx)
    Ymax = -1
    for Rey in Redyset:
        if Blx > Red[Rey]:
            Ymax = max(Ymax,Rey)
    if Ymax != -1:
        Redyset.remove(Ymax)
        Rey = Red.pop(Ymax)
        Ans +=1
print(Ans)

Submission status: Wrong Answer

Solution code:
import sys,math,collections,itertools
input = sys.stdin.readline

N = int(input())
red = []
blue=[]
for _ in range(N):
    a,b=list(map(int,input().split()))
    red.append([a,b,a**2+b**2])
for _ in range(N):
    a,b=list(map(int,input().split()))
    blue.append([a,b,a**2+b**2])

#赤のa**2+b**2の大きいものから見ていく
#青のa**2+b**2の大きいものからペアになれるか見る
#ペアになれる→カウントしてペアを除く
#青のa**2+b**2のほうがが小さくなってしまったらペアになれない。

red.sort(key = lambda x:x[2])
blue.sort(key = lambda x:x[2])
cnt =0
while red:
    a,b,r = red.pop()
    for bi in range(len(blue)):
        if blue[bi][2]<r:
            continue
        elif blue[bi][0]>a and blue[bi][1]>b:
            cnt +=1
            blue.pop(bi)
            break
print(cnt)

Submission status: Wrong Answer

Solution code:
import sys,math,collections,itertools
input = sys.stdin.readline

N = int(input())
red = []
blue=[]
for _ in range(N):
    a,b=list(map(int,input().split()))
    red.append([a,b,a**2+b**2])
for _ in range(N):
    a,b=list(map(int,input().split()))
    blue.append([a,b,a**2+b**2])

#赤のa**2+b**2の大きいものから見ていく
#青のa**2+b**2の大きいものからペアになれるか見る
#ペアになれる→カウントしてペアを除く
#青のa**2+b**2のほうがが小さくなってしまったらペアになれない。

red.sort(key = lambda x:x[2])
blue.sort(key = lambda x:x[2])
cnt =0
while red:
    a,b,r = red.pop()
    for bi in range(len(blue)-1,-1,-1):
        if blue[bi][2]<r:
            break
        elif blue[bi][0]>a and blue[bi][1]>b:
            cnt +=1
            blue.pop(bi)
            break
print(cnt)

Submission status: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline


def main():
    N = int(input())
    R = [[] for _ in range(2 * N)]
    B = [[] for _ in range(2 * N)]
    for _ in range(N):
        a, b = map(int, input().split())
        R[a].append(b)
    for _ in range(N):
        c, d = map(int, input().split())
        B[c].append(d)

    for i in range(2 * N):
        R[i].sort(reverse=True)
        B[i].sort(reverse=True)

    ans = 0
    Bx = 1
    for By_list in B:
        for By in By_list:
            Rx = Bx - 1
            for Ry_list in R[:Rx + 1][::-1]:
                is_found = False
                for Ry in Ry_list:
                    if Ry < By:
                        is_found = True
                        ans += 1
                        R[Rx].remove(Ry)
                        break
                if is_found:
                    break
                Rx -= 1
        Bx += 1

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline


def main():
    N = int(input())
    R = [[] for _ in range(2 * N)]
    B = [[] for _ in range(2 * N)]
    for _ in range(N):
        a, b = map(int, input().split())
        R[a].append(b)
    for _ in range(N):
        c, d = map(int, input().split())
        B[c].append(d)

    for i in range(2 * N):
        R[i].sort(reverse=True)
        B[i].sort(reverse=True)

    ans = 0
    Bx = 2 * N - 1
    for By_list in B[::-1]:
        for By in By_list:
            Rx = Bx - 1
            for Ry_list in R[:Rx + 1][::-1]:
                is_found = False
                for Ry in Ry_list:
                    if Ry < By:
                        is_found = True
                        ans += 1
                        R[Rx].remove(Ry)
                        break
                if is_found:
                    break
                Rx -= 1
        Bx -= 1

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

AB.sort(reverse=True)
CD.sort(reverse=True)

#print(AB)
#print(CD)

ans = 0
used = set()
for i in range(n):
    _, a, b = AB[i]
    for j in range(n):
        if j in used:
            continue
        _, c, d = CD[j]
        if a < c and b < d:
            ans += 1
            used.add(j)
            break
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
rl = []
bl = []
xs = [(-1,'',False)]*(2*n)
for _ in range(n):
    a,b = map(int, input().split())
    rl.append((a,b))
    xs[a] = (b,'r',False)


for _ in range(n):
    c,d = map(int, input().split())
    bl.append((c,d))
    xs[c] = (d,'b',False)

rl.sort()
bl.sort()

ans = 0
for rx,ry in rl:
    min_x,min_y = 10**5,10**5
    for x in range(rx,2*n):
        y,color,used = xs[x]
        if y > ry and color =='b' and not used and min_y > y:
            min_x = x
            min_y = y
    if min_x != 10**5:
        ans += 1
        xs[min_x] = (min_y,'b',True)

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

R = []
for _ in range(N):
    a, b = map(int, input().split())
    R.append((a, b))

B = []
for _ in range(N):
    c, d = map(int, input().split())
    B.append((c, d))

R.sort(key=lambda x: (x[0], x[1]))
B.sort(key=lambda x: (x[0], x[1]))

ans = 0
for a, b in R:
    for i in range(len(B)):
        if B[i][0] > a and B[i][1] > b:
            ans += 1
            B.pop(i)
            break
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

R = []
for _ in range(N):
    a, b = map(int, input().split())
    R.append((a, b))

B = []
for _ in range(N):
    c, d = map(int, input().split())
    B.append((c, d))

R.sort(key=lambda x: (x[0], x[1]))
B.sort(key=lambda x: (x[1], x[0]))

ans = 0
for a, b in R:
    for i in range(len(B)):
        if B[i][0] > a and B[i][1] > b:
            ans += 1
            B.pop(i)
            break
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
ab = []
for i in range(N):
    ab.append(list(map(int,input().split())))
cd = []
for i in range(N):
    cd.append(list(map(int,input().split())))
cd.sort()
#print(ab[2][1])
#print(cd[2][1])
ans = 0
for i in range(N):
    lis = []
    for j in range(len(ab)):
        #print(i,j)
        if cd[i][0] >= ab[j][0] and cd[i][1] >= cd[j][1]:
            lis.append(ab[j])
    if len(lis) > 0:
        lis.sort(key=lambda x:x[1])
        ans += 1
        ab.remove(lis[0])
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
ab = []
for i in range(N):
    ab.append(list(map(int,input().split())))
cd = []
for i in range(N):
    cd.append(list(map(int,input().split())))
lis = [[False] * N for i in range(N)]
for i in range(N):
    for j in range(N):
        if ab[i][0] < cd[j][0] and ab[i][1] < cd[j][1]:
            lis[i][j] = True
#print(lis)
ans = 0
#print(lis[0][0])
for i in range(N):
    if True in lis[i]:
        d = []
        for j in range(N):
            if lis[i][j] == True:
                cnt = 0
                for k in range(i,N):
                    if lis[k][j] == True:
                        cnt += 1
                d.append([cnt,j])
        #print(d)
        d.sort()
        for j in range(N):
            lis[j][d[0][1]] = False
        ans += 1
        #print(d[0][1])
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
ab = []
for i in range(N):
    #ab = list(map(int,input().split()))
    ab.append(list(map(int,input().split())))
cd = []
for i in range(N):
    #cd = list(map(int,input().split()))
    cd.append(list(map(int,input().split())))
lis = [[False] * N for i in range(N)]
for i in range(N):
    for j in range(N):
        if ab[i][0] < cd[j][0] and ab[i][1] < cd[j][1]:
            lis[i][j] = True
ans1 = 0
for i in range(N):
    if True in lis[i]:
        ans1 += 1
ans2 = 0
for j in range(N):
    flg = False
    for i in range(N):
        if lis[i][j] == True:
            flg = True
    if flg == True:
        ans2 += 1
print(min(ans1,ans2))

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
import heapq
n = int(input())

red = defaultdict(list)
for _ in range(n):
    a, b = map(int, input().split())
    red[b].append(a)

blue = defaultdict(list)
for _ in range(n):
    a, b = map(int, input().split())
    blue[b].append(a)

ans = 0
can_use = []
for i in range(1, 2*n):
    for x in red[i-1]:
        heapq.heappush(can_use, x)
    blue[i].sort()

    for b in blue[i]:
        if not can_use:
            break
        minr = heapq.heappop(can_use)
        if minr < b:
            ans += 1
        else:
            heapq.heappush(can_use, minr)
print(ans)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter
from bisect import bisect
n = int(input())
a = [tuple(map(int,input().split())) for i in range(n)]
b = [tuple(map(int,input().split())) for i in range(n)]
a.sort(key=itemgetter(1))
a.sort(key=itemgetter(0))
b.sort(key=itemgetter(1))
b.sort(key=itemgetter(0))

ans = 0
for l,r in b:
  ind = bisect(a,(l-1,r-1))
  if ind > 0:
    ans += 1
    k = a[ind-1]
    a.remove(k)
    
print(ans)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter
from bisect import bisect
n = int(input())
a = [tuple(map(int,input().split())) for i in range(n)]
b = [tuple(map(int,input().split())) for i in range(n)]
a.sort(key=itemgetter(1))
a.sort(key=itemgetter(0))
b.sort(key=itemgetter(1))
b.sort(key=itemgetter(0))

ans = 0
for l,r in b:
  ind = bisect(a,(l-1,r-1))
  if ind > 0:
    ans += 1
    a.remove(a[ind-1])
    
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import math
from collections import deque
import bisect

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def make_grid(h, w, num): return [[int(num)] * w for _ in range(h)]


def main():
	N = NI()
	R = [NLI() for _ in range(N)]
	B = {}
	for i in range(N):
		c, d = NMI()
		B[c] = d
	R.sort(key=lambda x: x[0])
	ans = 0
	for r in R:
		BX = sorted(list(B.keys()))
		idx = bisect.bisect_left(BX, r[0])
		if idx == len(BX):
			continue
		tmp_BX = BX[idx:]
		tmp_B = [[x, B[x]] for x in tmp_BX]
		tmp_B.sort(key=lambda x: x[1])
		for x,y in tmp_B:
			if y > r[1]:
				del B[x]
				ans += 1
				break

	print(ans)





if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
import sys
import math
from collections import deque
import bisect

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def make_grid(h, w, num): return [[int(num)] * w for _ in range(h)]


def main():
	N = NI()
	R = [NLI() for _ in range(N)]
	B = {}
	for i in range(N):
		c, d = NMI()
		B[c] = d
	R.sort(key=lambda x: x[0])
	ans = 0
	for r in R:
		BX = sorted(list(B.keys()))
		idx = bisect.bisect_left(BX, r[0])
		if idx == len(BX):
			continue
		tmp_by = 300
		tmp_bx = -1
		for bx in BX[idx:]:
			if r[1] < B[bx] < tmp_by:
				tmp_by = B[bx]
				tmp_bx = bx
		if tmp_bx != -1:
			del B[tmp_bx]
			ans += 1

	print(ans)





if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
import sys
import math
from collections import deque
import bisect

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def make_grid(h, w, num): return [[int(num)] * w for _ in range(h)]


def main():
	N = NI()
	R = [NLI() for _ in range(N)]
	B = {}
	for i in range(N):
		c, d = NMI()
		B[c] = d
	R.sort(key=lambda x: x[0], reverse=True)
	ans = 0
	for r in R:
		print(r)
		BX = sorted(list(B.keys()))
		idx = bisect.bisect_left(BX, r[0])

		tmp_by = 300
		tmp_bx = -1
		for bx in BX[idx:]:
			if B[bx] < tmp_by:
				tmp_by = B[bx]
				tmp_bx = bx
		if tmp_bx != -1:
			print(tmp_bx, B[tmp_bx])
			del B[tmp_bx]
			ans += 1

	print(ans)





if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
import sys
import math
from collections import deque
import bisect

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def make_grid(h, w, num): return [[int(num)] * w for _ in range(h)]


def main():
	N = NI()
	R = [NLI() for _ in range(N)]
	B = {}
	for i in range(N):
		c, d = NMI()
		B[c] = d
	R.sort(key=lambda x: x[0], reverse=True)
	ans = 0
	for r in R:
		BX = sorted(list(B.keys()))
		idx = bisect.bisect_left(BX, r[0])
		if idx == len(BX):
			continue
		res = 300
		tmp_bx = -1
		for bx in BX[idx:]:
			if B[bx] < res:
				res = B[bx]
				tmp_bx = bx
		if tmp_bx != -1:
			del B[tmp_bx]
			ans += 1

	print(ans)





if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
n = int(input())
red = []
blue = []

for _ in range(n):
    a,b = map(int,input().split())
    red.append((a,b))

for _ in range(n):
    c,d = map(int,input().split())
    blue.append((c,d))

red.sort(reverse=True)
blue.sort()

red_ok = [True]*n
blue_ok = [True]*n
point = 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]:
            if red_ok[i] and blue_ok[j]:
                point += 1
                red_ok[i] = False
                blue_ok[j] = False

print(point)

Submission status: Wrong Answer

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
ab = [inpl() for _ in range(n)]
cd = [inpl() for _ in range(n)]
ab.sort(key = lambda x:x[1])
cd.sort(key = lambda x:x[1])
ab = deque(ab)
for i in range(n):
    c,d = cd[i]
    a,b = ab[0]
    if a < c and b < d:
        ab.popleft()
print(n-len(ab))

Submission status: Wrong Answer

Solution code:
N = int(input())
red = []
for _ in range(N):
    a,b = map(int,input().split())
    red.append(tuple([a,b]))

blue = []
for _ in range(N):
    a,b = map(int,input().split())
    blue.append(tuple([a,b]))

red.sort(reverse=True)
blue.sort()

t = None
cnt = 0
for i in range(N):
    rx = red[i][0]
    ry = red[i][1]
    for j in range(len(blue)):
        bx = blue[j][0]
        if rx < bx:
            miny = 201
            for b in blue[j:]:
                if ry < b[1]:
                    if miny > b[1]:
                        miny = b[1]
                        t =b
                        break

    if t != None:
        # print(red[i],t)
        blue.remove(t)
        cnt += 1
    t = None

print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
red = []
for _ in range(N):
    a,b = map(int,input().split())
    red.append(tuple([a,b]))

blue = []
for _ in range(N):
    a,b = map(int,input().split())
    blue.append(tuple([a,b]))

red.sort(reverse=True)
blue.sort()

t = None
cnt = 0
for i in range(N):
    rx = red[i][0]
    for j in range(len(blue)):
        bx = blue[j][0]
        if rx < bx:
            miny = 201
            for b in blue[j:]:
                if miny > b[1]:
                    miny = b[1]
                    t =b
            break

    if t != None:
        blue.remove(t)
        cnt += 1
    t = None

print(cnt)

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    AB = []
    for _ in range(n):
        a, b = map(int, input().split())
        AB.append([a + b, a, b])
    CD = []
    for _ in range(n):
        c, d = map(int, input().split())
        CD.append([c + d, c, d])
    AB.sort(key=lambda x: x[0], reverse=True)
    CD.sort(key=lambda x: x[0])

    res = 0
    for i in range(n):
        _, a, b = AB[i]
        for j in range(len(CD)):
            _, c, d = CD[j]
            if a < c and b < d:
                res += 1
                CD.pop(j)
                break

    print(res)


if __name__ == '__main__':
    resolve()

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    AB = sorted([list(map(int, input().split())) for _ in range(n)], key=lambda x: [x[0], x[1]])
    CD = sorted([list(map(int, input().split())) for _ in range(n)], key=lambda x: [x[1], x[0]])

    res = 0
    for i in range(n):
        a, b = AB[i]
        for j in range(len(CD)):
            c, d = CD[j]
            if a < c and b < d:
                res += 1
                CD.pop(j)
                break

    print(res)


if __name__ == '__main__':
    resolve()

Submission status: Wrong Answer

Solution code:
N=int(input())

X=[]
Y=[]
for i in range(N):
    a,b=map(int, input().split())
    X.append([a,"red",i])
    Y.append([b,"red",i])

for i in range(N):
    c,d=map(int, input().split())
    X.append([c,"blue", i])
    Y.append([d, "blue", i])

X=sorted(X)
Y=sorted(Y)

xreds=0
xblues=0
L=[]
for t in X:
    x, color, i=t
    if color=="red":
        xreds+=1
    else:
        xblues+=1
        if xreds>xblues:
            L.append(i)
yreds=0
yblues=0
for t in Y:
    y, color, i=t
    if color=="red":
        yreds+=1
    else:
        yblues+=1
        if yreds<yblues:
            L.append(i)
#print(L)
print(N-len(set(L)))

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    AB = sorted([list(map(int, input().split())) for _ in range(n)], key=lambda x: x[0])
    CD = sorted([list(map(int, input().split())) for _ in range(n)], key=lambda x: x[1])

    res = 0
    for i in range(n):
        a, b = AB[i]
        for j in range(len(CD)):
            c, d = CD[j]
            if a < c and b < d:
                res += 1
                CD.pop(j)
                break

    print(res)


if __name__ == '__main__':
    resolve()

Submission status: Wrong Answer

Solution code:
n=int(input())

r=[[0 for i in range(2*n)] for j in range(2*n)]
num=[[0 for i in range(2*n+1)] for j in range(2*n+1)]
b=[]
cnt=0
for i in range(n):
  s,t=map(int,input().split())
  r[s][t]=1
#print(r)
for i in range(2*n):
  for j in range(2*n):
    num[i+1][j+1]=num[i][j+1]+num[i+1][j]-num[i][j]+r[i][j]
#print(num)
for i in range(n):
  s,t=map(int,input().split())
  b.append(num[s+1][t+1])
b.sort()
for i in b:
  if i>cnt:
    cnt+=1
print(cnt)

Submission status: Wrong Answer

Solution code:
n=int(input())

r=[[0 for i in range(2*n)] for j in range(2*n)]
num=[[0 for i in range(2*n+1)] for j in range(2*n+1)]
b=[]
cnt=0
for i in range(n):
  s,t=map(int,input().split())
  r[s][t]=1
#print(r)
for i in range(2*n):
  for j in range(2*n):
    num[i+1][j+1]=num[i][j+1]+num[i+1][j]-num[i][j]+r[i][j]
#print(num)
for i in range(n):
  s,t=map(int,input().split())
  b.append(num[s][t])
b.sort()
for i in b:
  if i>=cnt:
    cnt+=1
print(cnt)

Submission status: Wrong Answer

Solution code:
n=int(input())

r=[[0 for i in range(2*n)] for j in range(2*n)]
num=[[0 for i in range(2*n+1)] for j in range(2*n+1)]
b=[]
cnt=0
for i in range(n):
  s,t=map(int,input().split())
  r[s][t]=1
#print(r)
for i in range(2*n):
  for j in range(2*n):
    num[i+1][j+1]=num[i][j+1]+num[i+1][j]-num[i][j]+r[i][j]
#print(num)
for i in range(n):
  s,t=map(int,input().split())
  b.append(num[s][t])
b.sort()
for i in b:
  if i>cnt:
    cnt+=1
print(cnt)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[]
b=[]
for i in range(n):
    a.append(list(map(int,input().split())))
for i in range(n):
    b.append(list(map(int,input().split())))
e=[0 for i in range(n)]
a.sort()
b.sort()
count=0
for i in range(n):
    k=a[i]
    for j in range(n):
        if k[0]<b[j][0] and k[1]<b[j][1] and e[j]==0:
            count+=1
            e[j]+=1
            break
        if k[0]>b[j][0]:
            break
count1=0
f=[0 for i in range(n)]
b.sort(key=lambda x: x[1])
for i in range(n):
    k=a[i]
    for j in range(n):
        if k[0]<b[j][0] and k[1]<b[j][1] and f[j]==0:
            count1+=1
            f[j]+=1
            break
print(max(count,count1))

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    ab = [list(map(int,input().split())) for _ in range(n)]
    cd = [list(map(int,input().split())) for _ in range(n)]
    ab1 = sorted(ab,key=lambda x:(-x[0],-x[1]))
    cd1 = sorted(cd,key=lambda x:(-x[0],-x[1]))
    ab2 = sorted(ab,key=lambda x:(-x[1],-x[0]))
    cd2 = sorted(cd,key=lambda x:(-x[1],-x[0]))

    res1 = 0
    res2 = 0
    for i in range(n):
        if ab1[i][0] < cd1[i][0] and ab1[i][1] < cd1[i][1]:
            res1 += 1
        if ab2[i][0] < cd2[i][0] and ab2[i][1] < cd2[i][1]:
            res2 += 1
    print(max(res1,res2))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N=int(input())
A=[]
B=[[]for _ in range(N)]
C=[]
D=[[]for _ in range(N)]
for i in range(N):
    a,b=map(int,input().split())
    val=a**2+b**2
    A.append([i,a,b])

for i in range(N):
    c,d=map(int,input().split())
    val=c**2+d**2
    C.append([i,c,d])

for cnt,a,b in A:
    for num,c,d in C:
        if a<c and b<d:
            val=(a-c)**2+(b-d)**2
            B[cnt].append([val,num])

for i in range(N):
    B[i].sort(reverse=True)
chk=[0 for _ in range(N)]
ans=0
for cnt,a,b in A:
    for val,num in B[cnt]:
        if chk[num]==0:
            ans+=1
            chk[num]=1

print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=[]
B=[]
C=[]
D=[]
for i in range(N):
    a,b=map(int,input().split())
    val=a**2+b**2
    A.append([val,a,b])

for i in range(N):
    c,d=map(int,input().split())
    val=c**2+d**2
    C.append([val,c,d])

ans=0
A.sort(reverse=True)
C.sort(reverse=True)
#print(A)
#print(C)
cnt=0
chk=[0 for _ in range(N)]
for val,a,b in A:
    cnt=0
    while(1):
        if cnt>=N:
            break
        if chk[cnt]==1:
            cnt+=1
            continue
        c=C[cnt][1]
        d=C[cnt][2]
        if a<c and b<d:
            ans+=1
            chk[cnt]=1
            cnt+=1
            break
        cnt+=1
print(ans)

Submission status: Wrong Answer

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

def main():
  n = int(input())
  lr = [list(map(int, input().split()))+[0] for _ in range(n)] 
  lb = [list(map(int, input().split()))+[1] for _ in range(n)]
  lrb = sorted(lr + lb, key=lambda x: x[0])
  ignore = []
  
  rcnt = 0
  for x, y, c in lrb:
    if c == 0:
      rcnt += 1
    if c == 1:
      if rcnt == 0:
        ignore.append([x, y, c])
      else:
        rcnt -= 1
  
#   lrb = sorted(lr + lb, key=lambda x: x[1])
#   rcnt = 0
#   for x, y, c in lrb:
#     if [x, y, c] in ignore:
#       continue
#     if c == 0:
#       rcnt += 1
#     if c == 1:
#       if rcnt == 0:
#         ignore.append([x, y, c])
#       else:
#         rcnt -= 1
        
  print(n - len(ignore))
  

if __name__=='__main__':
  main()

Submission status: Wrong Answer

Solution code:
import sys,queue,math,copy,itertools,bisect,collections,heapq
sys.setrecursionlimit(10**7)
INF = 10**18
MOD = 10**9 + 7
LI = lambda : [int(x) for x in sys.stdin.readline().split()]
NI = lambda : int(sys.stdin.readline())

N = NI()
red = [LI() for _ in range(N)]
blue = [LI() for _ in range(N)]
pair = [[] for _ in range(N)]

for e,(c,d) in enumerate(blue):
    for r in red:
        if r[0] < c and r[1] < d:
            pair[e].append(r)

ans = 0
i = 1
while True:
    update = True
    while update:
        update = False
        for j in range(N):
            if blue[j] == []: continue
            num = 0
            for r in pair[j]:
                if r[0] >= 0:
                    z = r
                    num += 1
            if 0 < num <= i:
                ans += 1
                z[0] = -1
                blue[j] = []
                update = True
                i = 1
    i += 1
    if i >= N : break
print(ans)

Submission status: Wrong Answer

Solution code:
import sys,queue,math,copy,itertools,bisect,collections,heapq
sys.setrecursionlimit(10**7)
INF = 10**18
MOD = 10**9 + 7
LI = lambda : [int(x) for x in sys.stdin.readline().split()]
NI = lambda : int(sys.stdin.readline())

N = NI()
red = [LI() for _ in range(N)]
blue = [LI() for _ in range(N)]
pair = [[] for _ in range(N)]

for e,(c,d) in enumerate(blue):
    for r in red:
        if r[0] < c and r[1] < d:
            pair[e].append(r)

ans = 0
i = 1
while True:
    update = True
    while update:
        update = False
        for j in range(N):
            if blue[j] == []: continue
            num = 0
            for r in pair[j]:
                if r[0] >= 0:
                    z = r
                    num += 1
            if 0 < num <= i:
                ans += 1
                z[0] = -1
                blue[j] = []
                update = True
                i = 1
    i += 1
    if N - ans < i : break
print(ans)

Submission status: Wrong Answer

Solution code:
import sys,queue,math,copy,itertools,bisect,collections,heapq
sys.setrecursionlimit(10**7)
INF = 10**18
MOD = 10**9 + 7
LI = lambda : [int(x) for x in sys.stdin.readline().split()]
NI = lambda : int(sys.stdin.readline())

N = NI()
red = [LI() for _ in range(N)]
blue = [LI() for _ in range(N)]
pair = [[] for _ in range(N)]

for e,(c,d) in enumerate(blue):
    for r in red:
        if r[0] < c and r[1] < d:
            pair[e].append(r)

ans = 0
for i in range(1,N+1):
    update = True
    while update:
        update = False
        for j in range(N):
            if blue[j] == []: continue
            num = 0
            for r in pair[j]:
                if r[0] >= 0:
                    z = r
                    num += 1
            if 0 < num <= i:
                ans += 1
                z[0] = -1
                blue[j] = []
                update = True
    if N - ans < i : break
print(ans)

Submission status: Wrong Answer

Solution code:
# 赤：Y軸降順、X軸降順でソート
# 青：Y軸昇順、X軸昇順でソート
# 青を順に処理して、条件を満たす赤があれば採用する
N = int(input())

red = [None] * N
for i in range(N):
  red[i] = tuple(map(int,input().split()))

red = sorted(red, key = lambda x:(-x[1],-x[0]))

blue = [None] * N
for i in range(N):
  blue[i] = tuple(map(int,input().split()))

blue = sorted(blue, key = lambda x:(x[1],x[0]))

ans = 0
for b in blue:
  found = -1
  for i in range(len(red)):
    if red[i][0] < b[0] and red[i][1] < b[1]:
      ans += 1
      found = i
      break
  if found != -1:
    del red[found]

print(ans)

Submission status: Wrong Answer

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

red = sorted(red,key = lambda x:(x[0],-x[1]))
blue = sorted(blue,key = lambda x:(x[0],-x[1]))

ans = 0
for i in range(len(red)-1,-1,-1):
  x,y = red[i]
  for j in range(len(blue)-1,-1,-1):
    xb,yb = blue[j]
    if x < xb and y < yb:
      ans += 1
      blue.pop(j)
      break
      
print(ans)

Submission status: Wrong Answer

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

red = sorted(red,key = lambda x:x[0])
blue = sorted(blue,key = lambda x:x[0])

ans = 0
for i in range(len(red)-1,-1,-1):
  x,y = red[i]
  for j in range(len(blue)-1,-1,-1):
    xb,yb = blue[j]
    if x < xb and y < yb:
      ans += 1
      blue.pop(j)
      break
      
print(ans)

Submission status: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline


def read_values():
    return map(int, input().split())


def read_list():
    return list(read_values())


def func(N, mod):
    F = [1]
    for i in range(1, N + 1):
        F.append(F[-1] * i % mod)
    return F


def inv(a, mod):
    return pow(a, mod - 2, mod)


def C(F, a, b, mod):
    return F[a] * inv(F[b], mod) * inv(F[a - b], mod) % mod


def main():
    N = int(input())
    R = [tuple(read_values()) for _ in range(N)]
    B = [tuple(read_values()) for _ in range(N)]
    R.sort(key=lambda r: (r[1], r[0]), reverse=True)
    B.sort(key=lambda r: (r[1], r[0]), reverse=True)

    res = 0
    paired = [False] * N
    for bx, by in B:
        for i, (rx, ry) in enumerate(R):
            if paired[i]:
                continue

            if rx < bx and ry < by:
                res += 1
                paired[i] = True
                break

    print(res)


if __name__ == "__main__":
    main()