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 = []
for i in range(n):
    a, b = map(int, input().split())
    red.append((a, b))
 
blue = []
for i in range(n):
    c, d = map(int, input().split())
    blue.append((c, d))
 
red = sorted(red, key=lambda x: x[1])
blue.sort()
 
count = 0
while len(blue) >= 1:
    c, d = blue.pop()
    tmp = []
    r = []
    while len(red) >= 1:
        a, b = red.pop(0)
        if a < c and b < d:
            r.append((a, b))
        else:
            tmp.append((a, b))
    if len(r) >= 1:
        count += 1
        r = sorted(r, key=lambda x:x[1])
        r.pop()
        tmp.extend(r)
    red.extend(tmp)
print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
red = []
for i in range(n):
    a, b = map(int, input().split())
    red.append((a, b))
 
blue = []
for i in range(n):
    c, d = map(int, input().split())
    blue.append((c, d))
 
red = sorted(red, key=lambda x:x[1])
blue.sort()
 
count = 0
while len(blue) >= 1:
    c, d = blue.pop(0)
    tmp = []
    while len(red) >= 1:
        a, b = red.pop()
        if a < c and b < d:
            count += 1
            break
        else:
            tmp.append((a, b))
    tmp.sort()
    red.extend(tmp)
 
print(count)

Submission status: Wrong Answer

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

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

red.sort()
blue.sort()
count = 0
while len(blue) >= 1:
    c, d = blue.pop(0)
    tmp = []
    while len(red) >= 1:
        a, b = red.pop()
        if a < c and b < d:
            count += 1
            break
        else:
            tmp.append((a, b))
    tmp.sort()
    red.extend(tmp)

print(count)

Submission status: Wrong Answer

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

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

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

count = 0
while len(blue) >= 1:
    c, d = blue.pop()
    tmp = []
    r = []
    while len(red) >= 1:
        a, b = red.pop()
        if a < c and b < d:
            r.append((a, b))
        else:
            tmp.append((a, b))
    if len(r) >= 1:
        count += 1
        r = sorted(r, key=lambda x:x[1])
        r.pop()
        tmp.extend(r)
    red.extend(tmp)
print(count)

Submission status: Wrong Answer

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

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

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

count = 0
while len(blue) >= 1:
    c, d = blue.pop()
    tmp = []
    while len(red) >= 1:
        a, b = red.pop()
        if a < c and b < d:
            count += 1
            break
        else:
            tmp.append((a, b))
    tmp.sort()
    red.extend(tmp)

print(count)

Submission status: Wrong Answer

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

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

red.sort()
blue.sort()
count = 0
while len(blue) >= 1:
    c, d = blue.pop()
    tmp = []
    while len(red) >= 1:
        a, b = red.pop()
        if a < c and b < d:
            count += 1
            break
        else:
            tmp.append((a, b))
    tmp.sort()
    red.extend(tmp)

print(count)

Submission status: Wrong Answer

Solution code:
n = (int)(input())

r = []
b = []

for _ in range(n):
    x, y = map(int, input().split())
    r.append([x, y])

for _ in range(n):
    x, y = map(int, input().split())
    b.append([x, y])

r.sort(key=lambda x: (x[1], x[0]))
b.sort(key=lambda x: (x[0], x[1]))

print(r)
print(b)
ans = 0
used_r = []
for i in reversed(range(n)):
    for j in reversed(range(n)):
        if not j in used_r:
            if b[i][0] > r[j][0]:
                if b[i][1] > r[j][1]:
                    ans += 1
                    used_r.append(j)
                    break
print(ans)

Submission status: Wrong Answer

Solution code:
n = (int)(input())

r = []
b = []

for _ in range(n):
    x, y = map(int, input().split())
    r.append([x, y])

for _ in range(n):
    x, y = map(int, input().split())
    b.append([x, y])

r.sort(key=lambda x: (x[0], x[1]))
b.sort(key=lambda x: (x[1], x[0]))


ans = 0
used_r = []
for i in reversed(range(n)):
    for j in reversed(range(n)):
        if not j in used_r:
            if b[i][0] > r[j][0]:
                if b[i][1] > r[j][1]:
                    ans += 1
                    used_r.append(j)
                    break
print(ans)

Submission status: Wrong Answer

Solution code:
n = (int)(input())

r = []
b = []

for _ in range(n):
    x, y = map(int, input().split())
    r.append([x, y])

for _ in range(n):
    x, y = map(int, input().split())
    b.append([x, y])

r.sort(key=lambda x: (x[0], x[1]))
b.sort(key=lambda x: (x[0], x[1]))


ans = 0
used_r = []
for i in range(n):
    for j in reversed(range(n)):
        if not j in used_r:
            if b[i][0] > r[j][0]:
                if b[i][1] > r[j][1]:
                    ans += 1
                    used_r.append(j)
                    break
print(ans)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter

n = int(input())
a = []
r = []
b = []
for i in range(n):
  a = list(map(int,input().split()))
  a.append(a[0]**2 + a[1]**2)
  r.append(a)
for i in range(n):
  a = list(map(int,input().split()))
  a.append(a[0]**2 + a[1]**2)
  b.append(a)
r.sort(key = itemgetter(2))
b.sort(key = itemgetter(2))
c = 0
for i in range(n):
  for j in range(n):
    if r[i][0] < b[j][0] and r[i][1] < b[j][1]:
      b[j] = [0,0,0]
      c += 1
      break
print(c)

Submission status: Wrong Answer

Solution code:
n=int(input())
l,r=[],[]
for i in range(n):
    x,y=map(int,input().split())
    l.append((x,y))
l.sort()
l.sort(key=lambda a: a[1],reverse=True)
for i in range(n):
    x,y=map(int,input().split())
    r.append((x,y))
r.sort()
ans=0
chk=[1]*n
for i in range(n):
    for j in range(n):
        if l[i][0]<r[j][0] and l[i][1]<r[j][1] and chk[j]:
            print(l[i],r[j])
            chk[j]=0
            ans+=1
            break
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
l,r=[],[]
for i in range(n):
    x,y=map(int,input().split())
    l.append((x,y))
l.sort()
for i in range(n):
    x,y=map(int,input().split())
    r.append((x,y))
r.sort(key=lambda a: a[1])
r=r[::-1]
ans=0
chk=[1]*n
for i in range(n):
    for j in range(n):
        if l[i][0]<r[j][0] and l[i][1]<r[j][1] and chk[j]:
            chk[j]=0
            ans+=1
            break
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
l,r=[],[]
for i in range(n):
    x,y=map(int,input().split())
    l.append((x,y))
l.sort()
for i in range(n):
    x,y=map(int,input().split())
    r.append((x,y))
r.sort(key=lambda a: a[1])
r=r[::-1]
ans=0
chk=[1]*n
for i in range(n):
    for j in range(n):
        if l[i][0]<r[j][0] and l[i][1]<r[j][1] and chk[j]:
            chk[j]=0
            ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
red = []
for i in range(n):
    red.append(list(map(int, input().split())))
blue = []
for i in range(n):
    blue.append(list(map(int, input().split())))
check_1 = []
check_2 = []
for i in range(n):
    for j in range(n):
        if (red[i][0] < blue[j][0]) and (red[i][1] < blue[j][1]):
            check_1.append(i)
            check_2.append(j)
check_1_unique = list(set(check_1))
check_2_unique = list(set(check_2))
print(min(len(check_1_unique),len(check_2_unique)))

Submission status: Wrong Answer

Solution code:
N = int(input())
ar = []
br = []
for i in range(N):
    l = list(map(int,input().split(" ")))
    ar.append(l)
for i in range(N):
    l = list(map(int,input().split(" ")))
    br.append(l)
cr = sorted(ar,reverse=True)
dr = sorted(br,reverse=True)
count = 0
for c in cr:
    for i,d in enumerate(dr):
        if c[0] < d[0] and c[1] < d[1]:
            count += 1
            del dr[i]
            break
print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
red = []
blue = []
for i in range(n):
    red += [list(map(int,input().split()))]
for j in range(n):
    blue += [list(map(int,input().split()))]

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

ans = 0

for k in range(n):
    tmp = -1
    tmp2 = -1
    for l in range(len(red)):
        
        if (blue[k][0] >= red[l][0]) and (blue[k][1] >= red[l][1]):
            if tmp < red[l][1]:
                tmp = red[l][1]
                tmp2 = l
    if tmp2 >= 0:
        red.remove(red[l])
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
red = []
blue = []
for i in range(n):
    red += [list(map(int,input().split()))]
for j in range(n):
    blue += [list(map(int,input().split()))]

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

print(blue)
ans = 0

for k in range(n):
    tmp = -1
    tmp2 = -1
    for l in range(len(red)):
        
        if (blue[k][0] >= red[l][0]) and (blue[k][1] >= red[l][1]):
            if tmp < red[l][1]:
                tmp = red[l][1]
                tmp2 = l
    if tmp2 >= 0:
        red.remove(red[l])
        ans += 1
print(ans)
print(red)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[]
b=[]
cnt=0
for i in range(n):
  a.append(list(map(int,input().split())))
for i in range(n):
  b.append(list(map(int,input().split())))
a.sort()
b.sort()

for i in range(n):
  for j in range(n):
    if (a[i][0]<b[j][0])and(a[i][1]<b[j][1]):
      cnt+=1
      b[j][0]=0
      b[j][1]=0
      break
print(cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())

red = []
blue = []

for i in range(n):
     red.append(tuple(map(int, input().split())))
for i in range(n):
     blue.append(tuple(map(int, input().split())))

red1 = sorted(red)
red2 = list(reversed(red1))
blue1 = sorted(blue)
blue2 = list(reversed(blue1))

ans1 = 0
for c, d in blue1:
    for a, b in red1:
        if a < c and b < d:
                ans1 += 1
                red1.remove((a, b))
                break
        else:
            continue

ans2 = 0
for c, d in blue2:
    for a, b in red2:
        if a < c and b < d:
                ans2 += 1
                red2.remove((a, b))
                break
        else:
            continue
ans = max(ans1, ans2)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

red = []
blue = []

for i in range(n):
     red.append(tuple(map(int, input().split())))
for i in range(n):
     blue.append(tuple(map(int, input().split())))

red1 = list(reversed(sorted(red)))
blue1 = list(reversed(sorted(blue)))

ans1 = 0
for c, d in blue1:
    for a, b in red1:
        if a < c and b < d:
                ans1 += 1
                red1.remove((a, b))
                break
        else:
            continue

red2 = []
blue2 = []
for i in range(n):
    red2.append((red[i][1], red[i][0]))
    blue2.append((blue[i][1], blue[i][0]))

red2 = list(reversed(sorted(red2)))
blue2 = list(reversed(sorted(blue2)))

ans2 = 0
for d, c in blue2:
    for b, a in red2:
        if b < d and a < c:
                ans2 += 1
                red2.remove((b, a))
                break
        else:
            continue

ans = max(ans1, ans2)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

red = []
blue = []

for i in range(n):
     red.append(tuple(map(int, input().split())))
for i in range(n):
     blue.append(tuple(map(int, input().split())))

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

ans = 0
for c, d in blue:
    for a, b in red:
        if a < c and b < d:
                ans += 1
                red.remove((a, b))
                break
        else:
            continue
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
l,r=[],[]
for i in range(n):
    x,y=map(int,input().split())
    l.append((x,y))
l.sort()
for i in range(n):
    x,y=map(int,input().split())
    r.append((x,y))
r.sort()
ans=[0]*n
t=-1
#print(l)
#print(r)
for i,j in l:
    t+=1
    for x,y in r:
        if i<x and j<y:
            ans[t]+=1
        #else:
        #    break
chk=0
#print(ans)
for i in ans:
    if i-chk>0: chk+=1
print(chk)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
# -*- coding: UTF-8 -*-
n=int(input())
l,r=[],[]
for i in range(n):
    x,y=map(int,input().split())
    l.append((x,y))
l.sort()
for i in range(n):
    x,y=map(int,input().split())
    r.append((x,y))
r.sort()
ans=[0]*n
t=-1
for i,j in l:
    t+=1
    for x,y in r:
        if i<x and j<y:
            ans[t]+=1
        else:
            break
chk=0
for i in ans:
    if i-chk>0: chk+=1
print(chk)

Submission status: Wrong Answer

Solution code:
N = int(input())
R = [[] for i in range(N)]
B = [[] for i in range(N)]
for i in range(N):
  R[i] = [int(x) for x in input().split()]
for i in range(N):
  B[i] = [int(x) for x in input().split()]
G = [[] for i in range(2 * N)]
for i in range(N):
  for j in range(N):
    if R[i][0] < B[j][0] and R[i][1] < B[j][1]:
      G[i].append(N + j)
      G[N + j].append(i)
cnt = 0
while True:
  g_min = [N, N]
  for i in range(2 * N):
    if len(G[i]) > 0 and len(G[i]) < g_min[0]:
      g_min = [len(G[i]), i]
  if g_min[0] == N:
    break
  s = g_min[1]
  t = G[s][0]
  for i in G[s]:
    G[i].pop(G[i].index(s))
  for j in G[t]:
    G[j].pop(G[j].index(t))
  G[s] = []
  G[t] = []
  cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
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)]

xl = [set() for _ in range(2 * N + 1)]
yl = [set() for _ in range(2 * N + 1)]

for b in B:
    x, y = b
    for i in range(x):
        xl[i].add(b)
    for j in range(y):
        yl[j].add(b)

cands = []
for r in R:
    x, y = r
    s = xl[x] and yl[y]
    cands.append([r, len(s), s])

def f(cands, used, n):
    if not cands:
        return n
    ret = 0
    hd, tl = cands[0], cands[1:]
    r, _, s = hd
    for t in s - used:
        u = used.union({t})
        ret = max(ret, f(tl, u, n + 1))
    ret = max(ret, f(tl, used, n))
    return ret

import operator
cands.sort(key=operator.itemgetter(1))
print(f(cands, set(), 0))

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
iN = int(input())
aR = [(i,[int(_) for _ in input().split()]) for i in range(iN)]
aB = [(i,[int(_) for _ in input().split()]) for i in range(iN)]

dBR={} #青→赤 青からみた組の可能性
dRB={} #赤←青 赤からみた組の可能性
dBRc={}
dRBc={}
for i,eB in aB:
    for j,eR in aR:
        if eB[0] > eR[0] and eB[1] > eR[1]:
            if j in dRB:
                dRB[j].add(i)
            else:
                dRB[j] = {i}
            if i in dBR:
                dBR[i].add(j)
            else:
                dBR[i] = {j}

#組み合わせの数が両方少ない方から決めていく
dDicided = set()
for b,lb in sorted(map(lambda b:[b,len(dBR[b])],dBR),key=lambda x:x[1]):
    for r, lr in  sorted(map(lambda r :[r,len(dRB[r])], dBR[b]),key=lambda x:x[1]) :
        if r not in dDicided :
            dDicided.add(r)
            break
print(len(dDicided))

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
iN = int(input())
aR = [(i,[int(_) for _ in input().split()]) for i in range(iN)]
aB = [(i,[int(_) for _ in input().split()]) for i in range(iN)]

dBR={} #青→赤 青からみた組の可能性
dRB={} #赤←青 赤からみた組の可能性
dBRc={}
for i,eB in aB:
    for j,eR in aR:
        if eB[0] > eR[0] and eB[1] > eR[1]:
            if j in dRB:
                dRB[j].add(i)
            else:
                dRB[j]={i}
            if i in dBR:
                dBR[i].add(j)
                dBRc[i] += 1
            else:
                dBR[i] = {j}
                dBRc[i] = 1

#組み合わせの数が両方少ない方から決めていく
dDicided = set()
for k,v in sorted(dBRc.items(),key=lambda x:x[1]):
    for r, lr in  sorted(map(lambda r :[r,len(dRB[r])], dBR[k]),key=lambda x:x[1]) :
        if r not in dDicided :
            dDicided.add(r)
            break
print(len(dDicided))

Submission status: Wrong Answer

Solution code:
n=int(input())
data=[]


for i in range(n):
    tmp=[0]*3
    tmp[0],tmp[1]=map(int,input().split())
    data.append(tmp)

for i in range(n):
    tmp=[1]*3
    tmp[0],tmp[1]=map(int,input().split())
    data.append(tmp)    

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

ans=0
j=2*n-1
while(data[j][2]==0):
    j-=1

while(1):
    tmp=[data[j]]
    while(1):
        j-=1
        if(j==-1):
            break
        tmp.append(data[j])
        if(data[j][2]==0):
            break
    while(1):
        j-=1
        if(j<=-1):
            break
        if(data[j][2]==1):
            break
        else:
            tmp.append(data[j])
    
    tmp.sort(key=lambda x:x[1])
    red=0
    for t in tmp:
        if(t[2]==0):
            red+=1
        else:
            if(red>=1):
                ans+=1
                red-=1
    if(j<=-1):
        break

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
count = 0
red = []
blue = []
for i in range(N):
    x,y = map(int,input().split(" "))
    red.append([x,y])
for i in range(N):
    x,y = map(int,input().split(" "))
    blue.append([x,y])
blue.sort()
for i in range(N):
    x = blue[i][0]
    y = blue[i][1]
    xy = []
    ymax = 0
    for j in range(N):
        if (red[j][0] < x)and(red[j][1] < y):
            xy.append(red[j])
    if len(xy) == 0:
        continue
    else:
        num = 0
        for j in range(len(xy)):
            if ymax < xy[j][1]:
                ymax = xy[j][1]
                num = j
        red[red.index(xy[num])] = [101,101]
        count += 1
print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
count = 0
red = []
blue = []
for i in range(N):
    x,y = map(int,input().split(" "))
    a = x+y
    red.append([a,x,y])
for i in range(N):
    x,y = map(int,input().split(" "))
    a = x+y
    blue.append([a,x,y])
red.sort()
blue.sort()
for i in range(N):
    I = N - i - 1
    for j in range(N):
        J = N - j - 1
        if blue[J][0] == -1:
            continue
        elif blue[J][0]+2 < red[I][0]:
            break
        if (red[I][1] < blue[J][1])and(red[I][2] < blue[J][2]):
            count += 1
            blue[J][0] = -1
            break
print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
rs = [tuple(map(int,input().split())) for i in range(N)]
bs = [tuple(map(int,input().split())) for i in range(N)]

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

removed = [0]*N
ans = 0
for bx,by in bs:
    for ri in range(N):
        if removed[ri]: continue
        rx,ry = rs[ri]
        if rx < bx and ry < by:
            removed[ri] = 1
            ans += 1
            break
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
rs = [tuple(map(int,input().split())) for i in range(N)]
bs = [tuple(map(int,input().split())) for i in range(N)]

rs.sort(reverse=True)
bs.sort(reverse=True)

removed = [0]*N
ans = 0
for bx,by in bs:
    for ri in range(N):
        if removed[ri]: continue
        rx,ry = rs[ri]
        if rx < bx and ry < by:
            removed[ri] = 1
            ans += 1
            break
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
red = [list(map(int, input().split()))[::-1] for _ in range(n)]
red.sort()
red = red[::-1]
blue = [list(map(int, input().split())) for _ in range(n)]
blue.sort()
blue = blue[::-1]
ans = 0
for i in range(n):
    bb = blue[i]
    for j in range(n - ans):
        if bb[0] >= red[j][1] and bb[1] >= red[j][0]:
            ans += 1
            del red[j]
            break
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
red = [list(map(int, input().split()))[::-1] for _ in range(n)]
red.sort(reverse=True)
blue = [list(map(int, input().split())) for _ in range(n)]
blue.sort(reverse=True)
ans = 0
for i in range(n):
    bb = blue[i]
    for j in range(n - ans):
        if bb[0] >= red[j][1] and bb[1] >= red[j][0]:
            ans += 1
            del red[j]
            break
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [list(map(int,input().split())) for i in range(N)]
B = [list(map(int,input().split())) for i in range(N)]
res_list = []
for i in range(N):
    tmp_list = []
    for j in range(N):
        if A[i][0] < B[i][0] and A[i][1] < B[i][1]:
            tmp_list.append(j)
    res_list.append(tmp_list)

res = 0

for j in res_list:
    if j == []:
        res_list.remove(j)
            
for i in range(len(res_list)):
    flag = 0
    for j in range(N):
        if j in res_list[i]:
            res_list[i].remove(j)
            flag = 1
    if flag == 1:
        res += 1
print(res)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [list(map(int,input().split())) for i in range(N)]
B = [list(map(int,input().split())) for i in range(N)]
res_list = []
for i in range(N):
    tmp_list = []
    for j in range(N):
        if A[i][0] < B[i][0] and A[i][1] < B[i][1]:
            tmp_list.append(j)
    res_list.append(tmp_list)

res = 0
for i in range(N):
    for j in res_list:
        if j == []:
            res_list.remove(j)
            
for i in range(len(res_list)):
    flag = 0
    for j in range(N):
        if j in res_list[i]:
            flag = 1
    if flag == 1:
        res += 1
print(res)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
N = int(input())

abn = []
cdn = []
for i in range(N):
    abn.append(list(map(int, input().split())))
for i in range(N):
    cdn.append(list(map(int, input().split())))

abn.sort(key=lambda x:(x[0],x[1]))
abn.reverse()
cdn.sort(key=lambda x:(x[0],x[1]))

pare_cnt = 0
while len(abn) > 0:
    pre_pare_cnt_list = []
    for i in range(len(abn)):
        (a,b) = abn[i]
        pre_pare_cnt = 0
        for j in range(len(cdn)):
            (c,d) = cdn[j]
            if a < c and b < d:
                pre_pare_cnt += 1

        if pre_pare_cnt == 0:
            abn.pop(i)
            break
        else:
            pre_pare_cnt_list.append(pre_pare_cnt)

    if len(pre_pare_cnt_list) == 0:
        break

    for i in range(len(abn)):
        (a,b) = abn[i]
        pre_pare_cnt = 0
        pre_pare_idx = 0
        for j in range(len(cdn)):
            (c,d) = cdn[j]
            if a < c and b < d:
                pre_pare_cnt += 1
                pre_pare_idx = j

        if pre_pare_cnt == min(pre_pare_cnt_list):
            abn.pop(i)
            cdn.pop(pre_pare_idx)
            pare_cnt += 1
            break

print(pare_cnt)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
N = int(input())

abn = []
cdn = []
for i in range(N):
    abn.append(list(map(int, input().split())))
for i in range(N):
    cdn.append(list(map(int, input().split())))

abn.sort(key=lambda x:(x[0],x[1]))
cdn.sort(key=lambda x:(x[0],x[1]))

pare_cnt = 0
while len(abn) > 0:
    pre_pare_cnt_list = []
    for i in range(len(abn)):
        (a,b) = abn[i]
        pre_pare_cnt = 0
        for j in range(len(cdn)):
            (c,d) = cdn[j]
            if a < c and b < d:
                pre_pare_cnt += 1

        if pre_pare_cnt == 0:
            abn.pop(i)
            break
        else:
            pre_pare_cnt_list.append(pre_pare_cnt)

    if len(pre_pare_cnt_list) == 0:
        break
        
    for i in range(len(abn)):
        (a,b) = abn[i]
        pre_pare_cnt = 0
        pre_pare_idx = 0
        for j in range(len(cdn)):
            (c,d) = cdn[j]
            if a < c and b < d:
                pre_pare_cnt += 1
                pre_pare_idx = j

        if pre_pare_cnt == min(pre_pare_cnt_list):
            abn.pop(i)
            cdn.pop(pre_pare_idx)
            pare_cnt += 1
            break

print(pare_cnt)

Submission status: Wrong Answer

Solution code:
import numpy as np
import random

N = int(input())
A = []
B = []
C = []
D = []
E = []
ans = 0
for i in range(0,N):
  H = list(map(int,input().split()))
  A.append(H[0])
  B.append(H[1])
  
for i in range(0,N):
  H = list(map(int,input().split()))
  C.append(H[0])
  D.append(H[1])
  E.append(i)

for i in range(0, 25000):
  random.shuffle(E)
  a = 0
  for j in range(0,N):
    if A[j] < C[E[j]] and B[j] < D[E[j]]:
      a += 1
  ans = max(ans,a)
print(ans)

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)]
reds2 = sorted(reds,key=lambda x: x[0] if x[0] < x[1] else x[1])
blues2 = sorted(blues,key=lambda x: x[0] if x[0] < x[1] else x[1])
count = 0

for i in reds2:
  for j in blues2:
    if i[0] < j[0] and i[1] < j[1]:
      count += 1
      blues2.remove(j)
      break
print(count)

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(reds,key=lambda x: x[0] if x[0] < x[1] else x[1])
blues = sorted(blues,key=lambda x: x[0] if x[0] < x[1] else x[1])
count = 0

visied_r = [False]*n
visied_b = [False]*n

for i in range(len(reds)):
  for j in range(len(blues)):
    if reds[i][0] < blues[j][0] and reds[i][1] < blues[j][1] and visied_r[i] == False and visied_b[j] == False:
      count += 1
      visied_r[i] = True
      visied_b[j] =True
print(visied_b.count(True))

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(reds,key=lambda x: x[0] if x[0] < x[1] else x[1])
blues = sorted(blues,key=lambda x: x[0] if x[0] < x[1] else x[1])
count = 0

visied_r = [False]*n
visied_b = [False]*n

for i in range(len(reds)):
  for j in range(len(blues)):
    if i < len(reds) and j < len(blues):
      if reds[i][0] < blues[j][0] and reds[i][1] < blues[j][1] and visied_r[i] == False and visied_b[j] == False:
        count += 1
        visied_r[i] = True
        visied_b[j] =True
        continue
print(count)

Submission status: Wrong Answer

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

cd_set = set(cd)
ab_cands = []
for a, b in ab:
    cands = []
    for c, d in cd:
        if a < c and b < d:
            cands.append((c, d))
    ab_cands.append([cands, len(cands)])
ab_cands = sorted(ab_cands, key = lambda x: x[1])
# print(cd_contains)

ans = 0
for cands, _ in ab_cands:
    for cand in cands:
        if cand in cd_set:
            ans += 1
            cd_set.remove(cand)
            break
print(ans)

Submission status: Wrong Answer

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

ab_set = set(ab)
cd_contains = []
for c, d in cd:
    contain = []
    for a, b in ab:
        if a < c and b < d:
            contain.append((a, b))
    cd_contains.append([contain, len(contain)])

cd_contains = sorted(cd_contains, key = lambda x: x[1])
# print(cd_contains)
ans = 0
for cands, _ in cd_contains:
    for cand in cands:
        if cand in ab_set:
            ans += 1
            ab_set.remove(cand)
            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))

U = [False for _ in range(N)]
R.sort()

for c, d in B:
    mi = -1
    my = -1
    for i, (a, b) in enumerate(R):
        if not U[i] and a < c and b < d and my < b:
            mi = i
            my = b
    if mi != -1:
        U[mi] = True
print(U.count(True))

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

U = [False for _ in range(N)]
R.sort()

for c, d in B:
    mi = -1
    my = -1
    for i, (a, b) in enumerate(R):
        if not U[i] and a < c and b < d and my < d:
            mi = i
            my = b
    if mi != -1:
        U[mi] = True
print(U.count(True))

Submission status: Wrong Answer

Solution code:
num=int(input())
a_array=[]
b_array=[]
for n in range(2*num):
    elem=[int(n) for n in input().split()]
    if n < num:
        a_array.append(elem)
    else:
        b_array.append(elem)
a_array.sort(key=lambda x:x[1])
a_array.reverse()
b_array.sort(key=lambda x: x[0])
answer=0
for b_x, b_y in b_array:
    for a_x, a_y in a_array:
        if b_x > a_x and b_y > a_y:
            answer=answer+1
            a_array.remove([a_x,a_y])
print(answer)

Submission status: Wrong Answer

Solution code:
lisx = []
lix = []
lisy = []
liy = []
lisxma = []
lixma = []
lisyma = []
liyma = []
n = int(input())
for i in range(n):
  a,b = map(int,input().split())
  lisx.append([a,b])
  lisy.append([b,a])
  lisxma.append([a,b])
  lisyma.append([b,a])
for i in range(n):
  a,b = map(int,input().split())
  lix.append([a,b])
  liy.append([b,a])
  lixma.append([a,b])
  liyma.append([b,a])
lisx.sort()
lix.sort()
lisy.sort()
liy.sort()
lisxma.sort(reverse=True)
lixma.sort(reverse=True)
lisyma.sort(reverse=True)
liyma.sort(reverse=True)
cou = 0
co = 0
couma = 0
coma = 0
for i in range(n):
  for j in range(len(lix)):
    if lisx[i][0] < lix[j][0] and lisx[i][1] < lix[j][1]:
      cou += 1
      del lix[j]
      break
for i in range(n):
  for j in range(len(liy)):
    if lisy[i][0] < liy[j][0] and lisy[i][1] < liy[j][1]:
      co += 1
      del liy[j]
      break
for i in range(n):
  for j in range(len(lixma)):
    if lisxma[i][0] < lixma[j][0] and lisxma[i][1] < lixma[j][1]:
      couma += 1
      del lixma[j]
      break
for i in range(n):
  for j in range(len(liyma)):
    if lisyma[i][0] < liyma[j][0] and lisyma[i][1] < liyma[j][1]:
      coma += 1
      del liyma[j]
      break
print(max(cou,co,couma,coma))