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 = []
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()
blue.sort()
count = 0
for i in range(n):
    a, b = red.pop(0)
    for j in range(len(blue)):
        if (a < blue[j][0]) & (b < blue[j][1]):
            count += 1
            blue.pop(j)
            break
print(count)

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()
blue.sort()
count = 0
for i in range(n):
    a, b = red.pop(0)
    for j in range(len(blue)):
        if (a < blue[j][0]) & (b < blue[j][1]):
            count += 1
            blue.pop(j)
            break

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

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

flg = [0 for i in range(N)]

ans = 0

for i in range(N) :
    a,b = red[i]
    
    for j in range(N) :
        if flg[j] :
            continue
        
        c,d = blue[j]
        
        if (a < c) and (b < d) :
            flg[j] = 1
            ans += 1
            break

print(ans)

Submission status: Wrong Answer

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

A.sort()

cnt = 0
for cost,a,b in A:
    idx = -1
    mn_dif = 4*N+2
    for j in range(N):
        c,d,used = B[j]
        dif = c-a + b-d
        if a < c and b < d and used == 0 and mn_dif > dif:
            idx = j
            mn_dif = dif
    if idx != -1:
        B[idx][2] = 1
        cnt += 1
        # print(a,b,B[idx])
print(cnt)

Submission status: Wrong Answer

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

A.sort(reverse=True)

cnt = 0
for cost,a,b in A:
    idx = -1
    mn_dif = 5*N
    for j in range(N):
        c,d,used = B[j]
        dif = c-a + b-d
        if a < c and b < d and used == 0 and mn_dif > dif:
            idx = j
            mn_dif = dif
    if idx != -1:
        B[idx][2] = 1
        cnt += 1
        # print(a,b,B[idx])
print(cnt)

Submission status: Wrong Answer

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

A.sort(reverse=True)

cnt = 0
for cost,a,b in A:
    idx = -1
    mn_dif = 4*N+2
    for j in range(N):
        c,d,used = B[j]
        dif = c-a + b-d
        if a < c and b < d and used == 0 and mn_dif > dif:
            idx = j
            mn_dif = dif
    if idx != -1:
        B[idx][2] = 1
        cnt += 1
        # print(a,b,B[idx])
print(cnt)

Submission status: Wrong Answer

Solution code:
n=int(input())
R=[]
B=[]
for i in range(n):
    r=[int(i) for i in input().split()]
    R.append(r)
for i in range(n):
    b=[int(i) for i in input().split()]
    B.append(b)
ans=0
for b in B:
    stock=[]
    for r in R:
        if r[0]<b[0] and r[1]<b[1]:
            stock.append(r)
    if 0<len(stock):
        stock.sort(key=lambda x:x[1],reverse=True)
        red=stock[0]
        ans+=1
        R.remove(red)
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
R=[]
B=[]
for i in range(n):
    r=[int(i) for i in input().split()]
    R.append(r)
for i in range(n):
    b=[int(i) for i in input().split()]
    B.append(b)
ans=0
for b in B:
    stock=[]
    for r in R:
        if r[0]<b[0]:
            stock.append(r)
    if 0<len(stock):
        stock.sort(key=lambda x:x[1],reverse=True)
        red=stock[0]
        ans+=1
        R.remove(red)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

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

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

alist.sort(reverse=1)
blist.sort()
ans = 0
for i in range(N):
    for j in range(len(alist)):
        if blist[i][0] > alist[j][0] and blist[i][1] > alist[j][0]:
            ans += 1
            alist = alist[:j] + alist[j:]
            break

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
red = []
blue = []
found =False
for _ in range(N):
    red.append([int(i) for i in input().split()])
for _ in range(N):
    blue.append([int(i) for i in input().split()])

pre_pair = -1
pair = 0
while len(blue)>0 and len(red)>0:
    if pre_pair == pair:
        for i, r in enumerate(red):
            if blue[0][0] > r[0] and blue[0][1] > r[1]:
                pair += 1
                del red[i]
                del blue[0]
                break
    pre_pair = pair
    del_list_b = [0 for i in range(len(blue))]
    for j, b in enumerate(blue):
        del_list_a = [1 for i in range(len(red))]
        for i, r in enumerate(red):
            if b[0] > r[0] and b[1] > r[1]:
                del_list_a[i] = 0
                key = i
        if del_list_a.count(0) == 1:
            pair += 1
            del red[key]
            del_list_b[j] = 1
        elif del_list_a.count(0) == 0:
            del_list_b[j] = 1
    blue = [blue[i] for i in range(len(blue)) if del_list_b[i] == 0]


print(pair)

Submission status: Wrong Answer

Solution code:
N = int(input())
red = []
blue = []
pair = []
found =False
for _ in range(N):
    red.append([int(i) for i in input().split()])
for _ in range(N):
    c, d = [int(i) for i in input().split()]
    found = False
    for i, r in enumerate(red):
        if c > r[0] and d > r[1]:
            pair.append([r, [c, d]])
            del red[i]
            found =True
            break
    if not found:
        for p in pair:
            if c > p[0][0] and d > p[0][1]:
                for i, r in enumerate(red):
                    if p[1][0] > r[0] and p[1][0] > r[1]:
                        pair.append([r, [p[1][0], p[1][1]]])
                        p[1][0] = c
                        p[1][1] = d
                        del red[i]
                        break
print(len(pair))

Submission status: Wrong Answer

Solution code:
N = int(input())
n = 100
NONE = 0
RED = 1
BLUE = 2
grid = [[NONE for i in range(2*n)] for j in range(2*n)]
for _ in range(N):
    a, b = [int(i) for i in input().split()]
    grid[a][b] = RED
for _ in range(N):
    a, b = [int(i) for i in input().split()]
    grid[a][b] = BLUE

pair = 0
found = False
for i in range(n):
    for j in range(n):
        if grid[i][j] == RED:
            found = False
            for l in range(j,n):
                for m in range(i,n):
                    if grid[m][l] == BLUE:
                        grid[m][l] = NONE
                        pair += 1
                        found =True
                        break
                if found:
                    break

print(pair)

Submission status: Wrong Answer

Solution code:
N = int(input())
n = 100
NONE = 0
RED = 1
BLUE = 2
grid = [[NONE for i in range(2*n)] for j in range(2*n)]
for _ in range(N):
    a, b = [int(i) for i in input().split()]
    grid[a][b] = RED
for _ in range(N):
    a, b = [int(i) for i in input().split()]
    grid[a][b] = BLUE

pair = 0
found = False
for i in range(n):
    for j in range(n):
        if grid[i][j] == BLUE:
            found = False
            for l in range(j-1,-1,-1):
                for m in range(i-1,-1,-1):
                    if grid[m][l] == RED:
                        grid[m][l] = NONE
                        pair += 1
                        found =True
                        break
                if found:
                    break

print(pair)

Submission status: Wrong Answer

Solution code:
N = int(input())
n = 100
NONE = 0
RED = 1
BLUE = 2
grid = [[NONE for i in range(2*n)] for j in range(2*n)]
for _ in range(N):
    a, b = [int(i) for i in input().split()]
    grid[a][b] = RED
for _ in range(N):
    a, b = [int(i) for i in input().split()]
    grid[a][b] = BLUE

red = []
pair = 0
for i in range(n):
    for j in range(n):
        if grid[i][j] == BLUE:
            for m, r in enumerate(red):
                if r[0]<i and r[1]<j:
                    del red[m]
                    pair += 1
                    break
        elif grid[i][j] == RED:
            red.append([i,j])

print(pair)

Submission status: Wrong Answer

Solution code:
n = int(input())
red = [[0,0] for _ in range(n)]
blue = [[0,0] for _ in range(n)]

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

flag = [True]*n

red.sort(key = lambda x:(min(x),x[0]))
red = [red[n-i-1] for i in range(n)]

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

for i in range(n):
    for j in range(n):
        if flag[j] and red[j][0] < blue[i][0] and red[j][1] < blue[i][1]:
            flag[j] = False
            break

ans = 0
for i in range(n):
    if not flag[i]:
        ans += 1

print(ans)

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

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

ans=0
for b in blue:
    candi=[i for i in red if i[0]<b[0]]
    if candi:
        red.remove(sorted(candi, key=lambda x: x[1], reverse=True)[0])
        ans+=1

print(ans)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter
n = int(input())
red = [[int(i) for i in input().split()] for i in range(n)]
blue = [[int(i) for i in input().split()] for i in range(n)]

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

r = sorted(red,key=itemgetter(0))
b = sorted(blue,key=itemgetter(0))
ans1 = s(r,b)

r = sorted(red,key=itemgetter(1))
b = sorted(blue,key=itemgetter(1))
ans2 = s(r,b)
print(max(ans1,ans2))

Submission status: Wrong Answer

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

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

idx = 0
ans = 0
for xb, yb in B:
    for i in range(len(R)):
        if xb > R[i][0] and yb > R[i][1]:
            ans += 1
            R.remove(R[i])
            break
            
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

rs, bs = [], []  # (x, y, pair_flag)

for _ in range(N):
    rs.append(list(map(int, input().split())) + [0])

for _ in range(N):
    bs.append(list(map(int, input().split())) + [0])

rs.sort()
bs.sort(key=lambda x: x[1])

npair = 0
ir, ib = 0, 0
while ir < N:
    rx, ry, _ = rs[ir]
    ib = 0
    while ib < N:
        bx, by, paired = bs[ib]
        if not paired and rx < bx and ry < by:
            rs[ir][2] = bs[ib][2] = 1
            npair += 1
            break
        ib += 1
    ir += 1

print(npair)

Submission status: Wrong Answer

Solution code:
N = int(input())
R = sorted([list(map(int,input().split())) for i in range(N)], key=lambda x: x[0],reverse=False)
B = sorted([list(map(int,input().split())) for i in range(N)], key=lambda x: x[1],reverse=True)

ans = 0

start = 0

for a,b in R :
    for i in range(start,N) :
        c,d = B[i]
        if (c-a > 0) and (d-b > 0) :
            start = i+1
            ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
from bisect import bisect

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

Bx = []
By = []

for i in range(N) :
    c,d = map(int,input().split())
    Bx.append(c)
    By.append(d)

Bx = sorted(Bx)
By = sorted(By)

A = []

for a,b in R :
    calc = min(N-bisect(Bx,a), N-bisect(By,b))
    A.append(calc)

ans = min(A)

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

R = sorted([list(map(int,input().split())) for i in range(N)], key=lambda x: x[0])

B = [[0 for x in range(2*N)] for y in range(2*N)]
for i in range(N) :
    c,d = map(int,input().split())
    B[c][d] = 1


ans = 0

for a,b in R :
    flg = 0
    while True :
        a += 1
        b += 1
        
        if (a >= 2*N) or (b >= 2*N) :
            break
        
        for i in range(a,2*N) :
            if B[i][b] :
                B[i][b] = 0
                ans += 1
                flg = 1
                break
        
        if flg :
            break
        
        for i in range(b,2*N) :
            if B[a][i] :
                B[a][i] = 0
                ans += 1
                flg = 1
                break
        
        if flg :
            break

print(ans)

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

cnt1 = 0

used = [0 for i in range(N)]

for i in range(N) :
    a,b = R[i]
    for j in range(N) :
        c,d = B[j]
        
        if (c-a > 0) and (d-b > 0) and (not used[j]):
            cnt1 += 1
            used[j] = 1
            break

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

cnt2 = 0

used = [0 for i in range(N)]

for i in range(N) :
    a,b = R[i]
    for j in range(N) :
        c,d = B[j]
        
        if (c-a > 0) and (d-b > 0) and (not used[j]):
            cnt2 += 1
            used[j] = 1
            break

ans = max(cnt1,cnt2)

print(ans)

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

ans = 0

used = [0 for i in range(N)]

for i in range(N) :
    a,b = R[i]
    for j in range(N) :
        c,d = B[j]
        
        if (c-a > 0) and (d-b > 0) and (not used[j]):
            ans += 1
            used[j] = 1
            break
            
print(ans)

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

ans = 0
start = 0

for i in range(N) :
    a,b = R[i]
    for j in range(start,N) :
        c,d = B[j]
        
        if (c-a > 0) and (d-b > 0) :
            ans += 1
            start = j+1
            break
            
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = []
b = []
for i in range(N):
    str = input().split()
    a.append([int(str[0]),int(str[1])])

for i in range(N):
    str = input().split()
    b.append([int(str[0]),int(str[1])])

sortb = sorted(b, key = lambda x : x[1])
sorta = sorted(a, key = lambda x : x[1])

sorta.reverse()
sortb.reverse()
flagb = []
for i in range(N):
    flagb.append(True)

count = 0
for i in range(N):
    for j in range(N):
        if sorta[j][1] < sortb[i][1] and flagb[i] and sorta[j][0] < sortb[i][0]:
            count = count + 1
            flagb[j] = False

            break

print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = []
b = []
for i in range(N):
    str = input().split()
    a.append([int(str[0]),int(str[1])])

for i in range(N):
    str = input().split()
    b.append([int(str[0]),int(str[1])])

sortb = sorted(b, key = lambda x : x[1])
sorta = sorted(a, key = lambda x : x[1])

sorta.reverse()
#print(sorta)
#print(sortb)
flagb = []
for i in range(N):
    flagb.append(True)

count = 0
for i in range(N):
    for j in range(N):
        if sorta[i][1] < sortb[j][1] and flagb[j] and sorta[i][0] < sortb[j][0]:
            count = count + 1
            flagb[j] = False
            #print(j)
            #print(sorta[i][1])
            #print(sortb[j][1])
            #print(sorta[i][0])
            #print(sortb[j][0])
            break

print(count)

Submission status: Wrong Answer

Solution code:
label = {}
flow = {}
s, t = 'S', 'T'

def printpath(path):
    return
    for u, v in zip(path, path[1:]):
        print("%s -%d-> " % (label[u], flow[(u,v)]), end="")
    print("")

def printflow():
    print()
    for r in R:
        for b in edges[r]:
            print("  ", label[r], label[b], "s->r=%d"%flow[(s, r)], ", r->b=%d"%flow[(r, b)], ", b->t=%d"%flow[(b, t)])
            #print("  ", label[r], label[b], "r->s=%d"%flow[(r, s)], ", b->r=%d"%flow[(b, r)], ", t->b=%d"%flow[(t, b)])

def findpath(v, t, edges, flow, visited):
    visited.add(v)
    for u in edges[v]:
        if u in visited:
            continue
        if flow[(v, u)] == 1:
            continue
        if u == t:
            return [v, t]
        path = findpath(u, t, edges, flow, visited)
        if path:
            return [v] + path
    return None

def max_match(R, B, edges):

    # init edge b - t
    for b in B:
        flow[(b, t)] = 0
        flow[(t, b)] = 1
        edges[b].append(t)

    # init edge s - r
    for r in R:
        flow[(s, r)] = 0
        flow[(r, s)] = 1
        #edges[s].append(r)

        # init flow r - b
        for b in edges[r]:
            flow[(r, b)] = 0
            flow[(b, r)] = 1

    #printflow()
    change = True
    while change:
        change = False
        for r in R:
            if flow[(s, r)] == 1:
                continue
            path = findpath(r, t, edges, flow, set([s]))
            if not path:
                break
            path = [s] + path
            for u, v in zip(path, path[1:]):
                flow[(u, v)] = 1
                flow[(v, u)] = 0
            change = True
    return flow

def solve(R, B, edges):
    flow = max_match(R, B, edges)

    match = 0
    for r in R:
        for b in edges[r]:
            match += flow[(r, b)]
    return match
            

N = int(input())

R = [tuple([int(x) for x in input().split()]) for _ in range(N)]
B = [tuple([int(x) for x in input().split()]) for _ in range(N)]
for i, r in enumerate(R):
    label[r] = "R%d" % (i+1)
    #print(label[r], r)
for i, r in enumerate(B):
    label[r] = "B%d" % (i+1)
    #print(label[r], r)
label[s] = 'S'
label[t] = 'T'

edges = {}
for r in R:
    edges[r] = []
for b in B:
    edges[b] = []

for r in R:
    rx, ry = r
    for b in B:
        bx, by = b
        if rx < bx and ry < by:
            edges[r].append(b)
            edges[b].append(r)


print(solve(R, B, edges))

Submission status: Wrong Answer

Solution code:
label = {}
flow = {}
s, t = 'S', 'T'

def printpath(path):
    return
    for u, v in zip(path, path[1:]):
        print("%s -%d-> " % (label[u], flow[(u,v)]), end="")
    print("")

def printflow():
    return
    print()
    for r in R:
        for b in edges[r]:
            print("  ", label[r], label[b], "s->r=%d"%flow[(s, r)], ", r->b=%d"%flow[(r, b)], ", b->t=%d"%flow[(b, t)])
            #print("  ", label[r], label[b], "r->s=%d"%flow[(r, s)], ", b->r=%d"%flow[(b, r)], ", t->b=%d"%flow[(t, b)])

def findpath(v, t, edges, flow, visited):
    visited.add(v)
    for u in edges[v]:
        if u in visited:
            continue
        if flow[(v, u)] == 1:
            continue
        if u == t:
            return [v, t]
        path = findpath(u, t, edges, flow, visited)
        if path:
            return [v] + path
    return None

def max_match(R, B, edges):
    edges[s] = R
    for b in B:
        flow[(b, t)] = 0
        flow[(t, b)] = 1
        edges[b].append(t)

    for r in R:
        flow[(s, r)] = 0
        flow[(r, s)] = 1
        for b in edges[r]:
            flow[(r, b)] = 0
            flow[(b, r)] = 1

    for r in R:
        printflow() 
        if flow[(s, r)] == 1:
            continue
        path = findpath(r, t, edges, flow, set())
        if not path:
            break
        path = [s] + path
        printpath(path)
        for u, v in zip(path, path[1:]):
            flow[(u,v)] = 1
            flow[(v,u)] = 0
    return flow

def solve(R, B, edges):
    flow = max_match(R, B, edges)

    match = 0
    for r in R:
        for b in edges[r]:
            match += flow[(r, b)]
    return match
            

N = int(input())

R = [tuple([int(x) for x in input().split()]) for _ in range(N)]
B = [tuple([int(x) for x in input().split()]) for _ in range(N)]
for i, r in enumerate(R):
    label[r] = "R%d" % (i+1)
    #print(label[r], r)
for i, r in enumerate(B):
    label[r] = "B%d" % (i+1)
    #print(label[r], r)
label[s] = 'S'
label[t] = 'T'

edges = {}
for r in R:
    edges[r] = []
for b in B:
    edges[b] = []

for r in R:
    rx, ry = r
    for b in B:
        bx, by = b
        if rx < bx and ry < by:
            edges[r].append(b)
            edges[b].append(r)


print(solve(R, B, edges))

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)]
B_ = B[:]

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

for i, b in enumerate(B):
    matchR = [(j, r) for j, r in enumerate(R) if r[0] < b[0]]
    if matchR:
        matchR.sort(key=lambda x: x[1][1], reverse=True)
        del R[matchR[0][0]]
    else:
        B_[i] = None

print(len([b for b in B_ if b is not None]))

Submission status: Wrong Answer

Solution code:
lst1 = []
lst2 = []
N = int(input())
for i in range(N):
    lst1.append(list(map(int, input().split())))
for j in range(N):
    lst2.append(list(map(int, input().split())))
lst1.sort()
lst2.sort()
cnt = 0
for c,d in lst2:
    for i,(a,b) in enumerate(lst1):
        if a < c and b < d:
            cnt +=1 
            lst1.pop(i)
print(cnt)

Submission status: Wrong Answer

Solution code:
dat_r = []
dat_b = []

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

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

dat_r.sort(key=lambda x: (-x[0]-x[1], -x[1], -x[0]))
dat_b.sort(key=lambda x: (x[0]+x[1],+x[1], +x[0]))
#print("")
#print(dat_r)
#print(dat_b)
res = 0
"""
for i in range(n):
    for j in range(len(dat_b)):
        # print("{0} < {1} vs {2} < {3}".format(dat_r[i][0] ,dat_b[j][0] ,dat_r[i][1] ,dat_b[j][1]))
        if dat_r[i][0] < dat_b[j][0] and dat_r[i][1] < dat_b[j][1]:
            # print("ok")
            res += 1
            dat_b  = dat_b[0:j] + dat_b[j + 1:]
            break
print(res)
"""
for i in range(n):
    for j in range(len(dat_r)):
        #print("{0} < {1} vs {2} < {3}".format(dat_r[i][0] ,dat_b[j][0] ,dat_r[i][1] ,dat_b[j][1]))
        if dat_r[j][0] < dat_b[i][0] and dat_r[j][1] < dat_b[i][1]:
            #print("ok")
            res += 1
            dat_r  = dat_r[0:j] + dat_r[j + 1:]
            break
print(res)

Submission status: Wrong Answer

Solution code:
dat_r = []
dat_b = []

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

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

dat_r.sort(key=lambda x: (-x[0]-x[1], -x[1], -x[0]))
dat_b.sort(key=lambda x: (x[0]+x[1],+x[1], +x[0]))
print("")
print(dat_r)
print(dat_b)
res = 0
"""
for i in range(n):
    for j in range(len(dat_b)):
        # print("{0} < {1} vs {2} < {3}".format(dat_r[i][0] ,dat_b[j][0] ,dat_r[i][1] ,dat_b[j][1]))
        if dat_r[i][0] < dat_b[j][0] and dat_r[i][1] < dat_b[j][1]:
            # print("ok")
            res += 1
            dat_b  = dat_b[0:j] + dat_b[j + 1:]
            break
print(res)
"""
for i in range(n):
    for j in range(len(dat_r)):
        #print("{0} < {1} vs {2} < {3}".format(dat_r[i][0] ,dat_b[j][0] ,dat_r[i][1] ,dat_b[j][1]))
        if dat_r[j][0] < dat_b[i][0] and dat_r[j][1] < dat_b[i][1]:
            #print("ok")
            res += 1
            dat_r  = dat_r[0:j] + dat_r[j + 1:]
            break
print(res)

Submission status: Wrong Answer

Solution code:
dat_r = []
dat_b = []

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

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

dat_r.sort(key=lambda x: ( x[0], x[1]))
dat_b.sort(key=lambda x: (-x[0] -x[1], -x[0], -x[1]))
dat_b.sort(key=lambda x: (+x[1], +x[0]))

res = 0
"""
for i in range(n):
    for j in range(len(dat_b)):
        # print("{0} < {1} vs {2} < {3}".format(dat_r[i][0] ,dat_b[j][0] ,dat_r[i][1] ,dat_b[j][1]))
        if dat_r[i][0] < dat_b[j][0] and dat_r[i][1] < dat_b[j][1]:
            # print("ok")
            res += 1
            dat_b  = dat_b[0:j] + dat_b[j + 1:]
            break
print(res)
"""
for i in range(n):
    for j in range(len(dat_r)):
        #print("{0} < {1} vs {2} < {3}".format(dat_r[i][0] ,dat_b[j][0] ,dat_r[i][1] ,dat_b[j][1]))
        if dat_r[j][0] < dat_b[i][0] and dat_r[j][1] < dat_b[i][1]:
            #print("ok")
            res += 1
            dat_r  = dat_r[0:j] + dat_r[j + 1:]
            break
print(res)

Submission status: Wrong Answer

Solution code:
dat_r = []
dat_b = []

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

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

dat_r.sort(key=lambda x: (x[0] + x[1], x[0], x[1]))
dat_b.sort(key=lambda x: (-x[0] -x[1], -x[0], -x[1]))
dat_b.sort(key=lambda x: (+x[1], +x[0]))

res = 0
"""
for i in range(n):
    for j in range(len(dat_b)):
        # print("{0} < {1} vs {2} < {3}".format(dat_r[i][0] ,dat_b[j][0] ,dat_r[i][1] ,dat_b[j][1]))
        if dat_r[i][0] < dat_b[j][0] and dat_r[i][1] < dat_b[j][1]:
            # print("ok")
            res += 1
            dat_b  = dat_b[0:j] + dat_b[j + 1:]
            break
print(res)
"""
for i in range(n):
    for j in range(len(dat_r)):
        #print("{0} < {1} vs {2} < {3}".format(dat_r[i][0] ,dat_b[j][0] ,dat_r[i][1] ,dat_b[j][1]))
        if dat_r[j][0] < dat_b[i][0] and dat_r[j][1] < dat_b[i][1]:
            #print("ok")
            res += 1
            dat_r  = dat_r[0:j] + dat_r[j + 1:]
            break
print(res)

Submission status: Wrong Answer

Solution code:
dat_r = []
dat_b = []

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

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

dat_r.sort(key=lambda x: (x[0] + x[1], x[0], x[1]))
dat_b.sort(key=lambda x: (-x[0] -x[1], -x[0], -x[1]))
dat_b.sort(key=lambda x: (+x[1], +x[0]))

res = 0
for i in range(n):
    for j in range(len(dat_b)):
        # print("{0} < {1} vs {2} < {3}".format(dat_r[i][0] ,dat_b[j][0] ,dat_r[i][1] ,dat_b[j][1]))
        if dat_r[i][0] < dat_b[j][0] and dat_r[i][1] < dat_b[j][1]:
            # print("ok")
            res += 1
            dat_b  = dat_b[0:j] + dat_b[j + 1:]
            break

print(res)

Submission status: Wrong Answer

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


r.sort()
l.sort(key=lambda x:x[1],reverse=1)
ans=0
for s,t in r.copy():
    for p,q in l.copy():
        if s<p and t<q:
            ans+=1
            r.remove((s,t))
            l.remove((p,q))
            break
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)]
red = sorted(red, key = lambda x: x[1])
blue.sort()
ans = 0
for i in range(n):
    a = 0
    for j in range(len(red)):
        if blue[i][0] > red[j][0] and blue[i][1] > red[j][1]:
            a = j
    if blue[i][0] > red[a][0] and blue[i][1] > red[a][1]:
        ans += 1
        del red[a]
        print(red)
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)]
red.sort()
blue = sorted(blue, key = lambda x: x[1])
ans = 0
for i in range(n):
    for j in range(len(red)):
        a = 0
        if blue[i][0] > red[j][0] and blue[i][1] > red[j][1]:
            a = j
    if blue[i][0] > red[a][0] and blue[i][1] > red[a][1]:
        ans += 1
        del red[a]
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)]
red.sort()
blue.sort()
ans = 0
for i in range(n):
    if blue[i][0] > red[0][0] and blue[i][1] > red[0][1]:
        ans += 1
        del red[0]
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)]
red.sort()
blue.sort()
ans = 0
for i in range(n):
    if red[i][0] > blue[0][0] and red[i][1] > blue[0][1]:
        ans += 1
        del blue[0]
print(ans)

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: max(x[0], x[1]), reverse=True)
blue.sort(key=lambda x: x[1])
blue.sort(key=lambda x: x[0])
ans = 0
for r in red:
    for b in blue:
        if r[0] <= b[0] and r[1] <= b[1]:
            ans += 1
            blue.remove(b)
            break
print(ans)

Submission status: Wrong Answer

Solution code:
n,*t=map(int,open(0).read().split())
x=sorted(zip(t[:n*2:2],t[1:n*2:2]))
y=sorted(zip(t[n*2::2],t[n*2+1::2]))
c=0
while y:
  i,j=y.pop()
  k=len(x)-1
  while k>=0:
    a,b=x[k]
    if a<i and b<j:
      c+=1
      del x[k]
      break
    k-=1
print(c)

Submission status: Wrong Answer

Solution code:
n,*t=map(int,open(0).read().split())
x=sorted(zip(t[:n*2:2],t[1:n*2:2]))
y=sorted(zip(t[n*2::2],t[n*2+1::2]))
c=0
while y:
  i,j=y.pop()
  t=[]
  while x:
    a,b=x.pop()
    if a<i and b<j:
      c+=1
      break
    t+=[(a,b)]
  x+=t[::-1]
print(c)