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())
AB = [list(map(int,input().split())) for i in range(N)]
CD = [list(map(int,input().split())) for i in range(N)]

AB.sort()
CD.sort()

#print(AB)
#print(CD)

li = [[] for i in range(N)]

for i in range(N):
    ab = AB[i]
    for j in range(N):
        cd = CD[j]
        if ab[0] < cd[0] and ab[1] < cd[1]:
            li[i].append(cd)

#print(li)

newli = []
for i in range(N):
    if li[i] != []:
        newli.append(li[i])
    else:
        N -= 1

li = newli

ans = 0
while len(li) != 0:
    l = 1000
    
    for i in range(N):
        l = min(l,len(li[i]))

    numli = []
    for i in range(N):
        if len(li[i]) == l:
            numli.append(i)
    rem = li[numli[-1]].pop()
    li.remove(li[numli[-1]])
    N -= 1
    ans += 1

    for j in range(N):
        if rem in li[j]:
            li[j].remove(rem)

    newli = []
    for i in range(N):
        if li[i] != []:
            newli.append(li[i])
        else:
            N -= 1

    li = newli

print(ans)

Submission status: Wrong Answer

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

AB.sort()
CD.sort()

#print(AB)
#print(CD)

li = [[] for i in range(N)]

for i in range(N):
    ab = AB[i]
    for j in range(N):
        cd = CD[j]
        if ab[0] < cd[0] and ab[1] < cd[1]:
            li[i].append(cd)

#print(li)

newli = []
for i in range(N):
    if li[i] != []:
        newli.append(li[i])
    else:
        N -= 1

li = newli

ans = 0
while len(li) != 0:
    l = 1000
    
    for i in range(N):
        l = min(l,len(li[i]))

    numli = []
    for i in range(N):
        if len(li[i]) == l:
            numli.append(i)
    rem = li[numli[-1]].pop(0)
    li.remove(li[numli[-1]])
    N -= 1
    ans += 1

    for j in range(N):
        if rem in li[j]:
            li[j].remove(rem)

    newli = []
    for i in range(N):
        if li[i] != []:
            newli.append(li[i])
        else:
            N -= 1

    li = newli

print(ans)

Submission status: Wrong Answer

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

AB.sort()
CD.sort()

#print(AB)
#print(CD)

li = [[] for i in range(N)]

for i in range(N):
    ab = AB[i]
    for j in range(N):
        cd = CD[j]
        if ab[0] < cd[0] and ab[1] < cd[1]:
            li[i].append(cd)

#print(li)

newli = []
for i in range(N):
    if li[i] != []:
        newli.append(li[i])
    else:
        N -= 1

li = newli

ans = 0
while len(li) != 0:
    l = 1000
    
    for i in range(N):
        l = min(l,len(li[i]))

    for i in range(N):
        if len(li[i]) == l:
            rem = li[i].pop(0)
            li.remove(li[i])
            N -= 1
            ans += 1
            break
    

    for j in range(N):
        if rem in li[j]:
            li[j].remove(rem)

    newli = []
    for i in range(N):
        if li[i] != []:
            newli.append(li[i])
        else:
            N -= 1

    li = newli

print(ans)

Submission status: Wrong Answer

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

AB.sort()
CD.sort()

#print(AB)
#print(CD)

li = [[] for i in range(N)]

for i in range(N):
    ab = AB[i]
    for j in range(N):
        cd = CD[j]
        if ab[0] < cd[0] and ab[1] < cd[1]:
            li[i].append(cd)

#print(li)

newli = []
for i in range(N):
    if li[i] != []:
        newli.append(li[i])
    else:
        N -= 1

li = newli

ans = 0
while len(li) != 0:
    l = 1000
    
    for i in range(N):
        l = min(l,len(li[i]))

    for i in range(N):
        if len(li[i]) == l:
            rem = li[i].pop()
            li.remove(li[i])
            N -= 1
            ans += 1
            break
    

    for j in range(N):
        if rem in li[j]:
            li[j].remove(rem)

    newli = []
    for i in range(N):
        if li[i] != []:
            newli.append(li[i])
        else:
            N -= 1

    li = newli

print(ans)

Submission status: Wrong Answer

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

AB.sort()
CD.sort()

#print(AB)
#print(CD)

li = [[] for i in range(N)]

for i in range(N):
    ab = AB[i]
    for j in range(N):
        cd = CD[j]
        if ab[0] < cd[0] and ab[1] < cd[1]:
            li[i].append(cd)

#print(li)

newli = []
for i in range(N):
    if li[i] != []:
        newli.append(li[i])
    else:
        N -= 1

li = newli

ans = 0
while len(li) != 0:
    l = 1000
    
    for i in range(N):
        l = min(l,len(li[i]))

    for i in range(N):
        if len(li[i]) == l:
            rem = li[i].pop()
            remli = li[i]
            ans += 1
            break

    for j in range(N):
        if rem in li[j]:
            li[j].remove(rem)

    newli = []
    for i in range(N):
        if li[i] != []:
            newli.append(li[i])
        else:
            N -= 1

    li = newli

print(ans)

Submission status: Wrong Answer

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

AB.sort()
CD.sort()

#print(AB)
#print(CD)

li = [[] for i in range(N)]

for i in range(N):
    ab = AB[i]
    for j in range(N):
        cd = CD[j]
        if ab[0] < cd[0] and ab[1] < cd[1]:
            li[i].append(cd)

#print(li)

newli = []
for i in range(N):
    if li[i] != []:
        newli.append(li[i])
    else:
        N -= 1

li = newli

ans = 0
while len(li) != 0:
    l = 1000
    
    for i in range(N):
        l = min(l,len(li[i]))

    for i in range(N):
        if len(li[i]) == l:
            rem = li[i].pop()
            remli = li[i]
            ans += 1
            break
    li.remove(remli)
    N -= 1

    for j in range(N):
        if rem in li[j]:
            li[j].remove(rem)

    newli = []
    for i in range(N):
        if li[i] != []:
            newli.append(li[i])
        else:
            N -= 1

    li = newli

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
ai = []
bi = []
pair = 0
for na in range(N):
    ai.append(list(map(int, input().split())))
for nb in range(N):
    bi.append(list(map(int, input().split())))
for i in range(N):
    flag = 0
    for j in range(2):
        if ai[i][j] < bi[i][j]:
            flag += 1
    if flag == 2:
        pair += 1
print(pair)

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

include=[]
for i in range(n):
    num=0
    for g in range(n):
        if a[g][0]<b[i][0] and a[g][1]<b[i][1]:
            num+=1
    include.append([num,i])
include.sort(key=lambda x: x[0])

_b=[]
for i in range(n):
    _b.append(b[include[i][1]])

ans=0
included = [0]*n
for i in range(n):
    for g in range(n):
        if a[g][0]<_b[i][0] and a[g][1]<_b[i][1] and included[g]==0:
            ans+=1
            included[g]=1
            break
print(ans)

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

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


X.sort(key=lambda x: x[0])
Y.sort(key=lambda x: x[1])

B = []
result = 0

for x in range(N):
  red = list(map(int, X[x]))

  for y in range(N):
    blue = list(map(int, Y[y]))
    if y in B:
      continue
    if red[0] < blue[0] and red[1] < blue[1]:
      result += 1
      B.append(y)
      break
  
print(result)

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.sort(key=lambda x: x[0])
AB.sort(key=lambda x: x[1])
CD.sort(key=lambda x: x[0])
CD.sort(key=lambda x: x[1])
AB_flags = [True] * N
CD_flags = [True] * N
ans = 0
for i in range(N):
    for j in range(N):
        if AB_flags[i] and CD_flags[j]:
            if AB[i][0] < CD[j][0] and AB[i][1] < CD[j][1]:
                ans += 1
                AB_flags[i] = False
                CD_flags[j] = False
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)]

a.sort(reverse=True)
b.sort()
idxb = list()
for i in range(n):
    idx = -1
    maxy = -1
    for j in range(n):
        if not j in idxb:
            if a[i][0] < b[j][0] and maxy < a[i][1] < b[j][1] :
                maxy = a[i][1]
                idx = j
    if idx != -1:
        idxb.append(idx)

print(len(idxb))

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

a.sort(reverse=True)
b.sort()
idxb = list()
for i in range(n):
    idx = -1
    maxy = -1
    for j in range(n):
        if not j in idxb:
            if a[i][0] < b[j][0] and maxy < a[i][1] < b[j][1] :
                miny = a[i][1]
                idx = j
    if idx != -1:
        idxb.append(idx)

print(len(idxb))

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

a.sort(reverse=True)
b.sort()
idxb = list()
for i in range(n):
    idx = -1
    miny = 1e+9
    for j in range(n):
        if not j in idxb:
            if a[i][0] < b[j][0] and a[i][1] < b[j][1] < miny:
                miny = b[i][1]
                idx = j
    if idx != -1:
        idxb.append(idx)

print(len(idxb))

Submission status: Wrong Answer

Solution code:
from operator import itemgetter

N=int(input())
A=[]
B=[]
for i in range(N):
  temp=list(map(int, input().split()))
  A.append(temp)
for i in range(N):
  temp=list(map(int, input().split()))
  B.append(temp)
  

def main():
  A.sort(key=itemgetter(0,1))
  B.sort(key=itemgetter(0,1))
  cnt=0
  while B!=[]:
    idx=-1
    for i in range(len(A)):
      if A[i][0]>=B[0][0]:
        break
      if A[i][0]<B[0][0] and A[i][1]<B[0][1]:
        idx=i
    if idx!=-1:
      cnt+=1
      del A[idx]
      del B[0]
    else:
      del B[0]
  print(cnt)

main()

Submission status: Wrong Answer

Solution code:
from operator import itemgetter

N=int(input())
A=[]
B=[]
for i in range(N):
  temp=list(map(int, input().split()))
  A.append(temp)
for i in range(N):
  temp=list(map(int, input().split()))
  B.append(temp)
  

def main():
  A.sort(key=itemgetter(0,1))
  B.sort(key=itemgetter(0,1))
  cnt=0
  while B!=[]:
    idx=-1
    for i in range(len(A)):
      if A[i][0]>=B[0][0]:
        break
      if A[i][0]<B[0][0] and A[i][1]<B[0][1]:
        idx=i
    if idx!=-1:
      cnt+=1
      del A[i]
      del B[0]
    else:
      del B[0]
  print(cnt)

main()

Submission status: Wrong Answer

Solution code:

N = int(input())

RED = []
BLUE = []

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

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

RED.sort(reverse=True)
BLUE.sort(reverse=True)

SELECTED_RED = set()
SELECTED_BLUE = set()

for i in range(N):
  for j in range(N):
    if i in SELECTED_RED or j in SELECTED_BLUE:
       continue
    
    a, b = RED[i]
    c, d = BLUE[j]
    if a < c and b < d:
      SELECTED_RED.add(i)
      SELECTED_BLUE.add(j)

print(len(SELECTED_RED))

Submission status: Wrong Answer

Solution code:
from operator import itemgetter

N = int(input())
reds = []
for i in range(N):
    a,b = map(int, input().split())
    reds.append((a,b))
blues = []
for i in range(N):
    a,b = map(int, input().split())
    blues.append((a,b))

reds = sorted(reds,key=itemgetter(0,1),reverse=True)
blues = sorted(blues,key=itemgetter(1))
blues = sorted(blues,reverse=True)

cnt = 0
while len(blues) > 0:
    c,d = blues.pop() #大きい順に
    # print("hoge",c,d)
    for a,b in reds:
        if c > a and d > b:
            # print((c,d),(a,b))
            reds.remove((a,b))
            cnt += 1
            break
print(cnt)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter

N = int(input())
reds = []
for i in range(N):
    a,b = map(int, input().split())
    reds.append((a,b))
blues = []
for i in range(N):
    a,b = map(int, input().split())
    blues.append((a,b))

reds = sorted(reds,key=itemgetter(0,1),reverse=True)
blues = sorted(blues,key=itemgetter(0,1))

cnt = 0
while len(blues) > 0:
    c,d = blues.pop() #大きい順に
    for a,b in reds:
        if c > a and d > b:
            # print((c,d),(a,b))
            reds.remove((a,b))
            cnt += 1
            break
print(cnt)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter

N = int(input())
reds = []
for i in range(N):
    a,b = map(int, input().split())
    reds.append((a,b))
blues = []
for i in range(N):
    a,b = map(int, input().split())
    blues.append((a,b))

reds = sorted(reds,key=itemgetter(0,1),reverse=True)
blues.sort()

cnt = 0
while len(blues) > 0:
    c,d = blues.pop() #大きい順に
    for a,b in reds:
        if c > a and d > b:
            # print((c,d),(a,b))
            reds.remove((a,b))
            cnt += 1
            break
print(cnt)

Submission status: Wrong Answer

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

reds.sort(reverse=True)
blues.sort()

# print(reds)
# print(blues)

cnt = 0
while len(blues) > 0:
    c,d = blues.pop() #大きい順に
    for a,b in reds:
        if c > a and d > b:
            # print((c,d),(a,b))
            reds.remove((a,b))
            cnt += 1
            break
print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
pointR = []
pointB = []
for i in range(N):
    pointR.append(list(map(int, input().split())))
for i in range(N):
    pointB.append(list(map(int, input().split())))
pointR.sort(key = lambda t: t[0], reverse = True)
pointB.sort(key = lambda t: t[0])
ans = 0

Aok = [True] * N
Bok = [True] * N

for i in range(N):
    for j in range(N):
        if Aok[j] and Bok[i]:
            if pointR[j][0] < pointB[i][0] and pointR[j][1] < pointB[i][1]:
                ans += 1
                Aok[j] = False
                Bok[i] = False
                break
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
pointR = []
pointB = []
for i in range(N):
    pointR.append(list(map(int, input().split())))
for i in range(N):
    pointB.append(list(map(int, input().split())))
pointR.sort(key = lambda t: t[0], reverse = True)
pointB.sort(key = lambda t: t[0], reverse = True)
ans = 0

Aok = [True] * N
Bok = [True] * N

for i in range(N):
    for j in range(N):
        if Aok[j] and Bok[i]:
            if pointR[j][0] < pointB[i][0] and pointR[j][1] < pointB[i][1]:
                ans += 1
                Aok[j] = False
                Bok[i] = False
                break
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
pointR = []
pointB = []
for i in range(N):
    pointR.append(list(map(int, input().split())))
for i in range(N):
    pointB.append(list(map(int, input().split())))
pointR.sort(key = lambda t: t[0], reverse = True)
pointB.sort(key = lambda t: t[0], reverse = True)
ans = 0

Aok = [True] * N

for i in range(N):
    for j in range(N):
        if Aok[j]:
            if pointR[j][0] < pointB[i][0] and pointR[j][1] < pointB[i][1]:
                ans += 1
                Aok[j] = False
                break
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys

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

    ab.sort(key=lambda x: x[0])
    cd.sort(key=lambda x: x[1])
    
    answer_j = []
    for i in range(N):
        a,b = ab[i]

        for j in range(N):

            if j in answer_j:
                continue
            c,d = cd[j]
            if a<c and b<d:
                answer_j.append(j)
                break

    print(len(answer_j))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
pointR = []
pointB = []
for i in range(N):
    pointR.append(list(map(int, input().split())))
for i in range(N):
    pointB.append(list(map(int, input().split())))
pointR.sort(key = lambda t: t[0])
pointB.sort(key = lambda t: t[0])
ans = 0

Bok = [True] * N

for i in range(N):
    for j in range(N):
        if Bok[j]:
            if pointR[i][0] < pointB[j][0] and pointR[i][1] < pointB[j][1]:
                ans += 1
                Bok[j] = False
                break
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
pointR = []
pointB = []
for i in range(N):
    pointR.append(list(map(int, input().split())))
for i in range(N):
    pointB.append(list(map(int, input().split())))
pointR.sort(key = lambda t: (t[0], t[1]), reverse = True)
pointB.sort(key = lambda t: (t[0], t[1]), reverse = True)
ans = 0

Bok = [True] * N

for i in range(N):
    for j in range(N):
        if Bok[j]:
            if pointR[i][0] < pointB[j][0] and pointR[i][1] < pointB[j][1]:
                ans += 1
                Bok[j] = False
                break
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
pointR = []
pointB = []
for i in range(N):
    pointR.append(list(map(int, input().split())))
for i in range(N):
    pointB.append(list(map(int, input().split())))
pointR.sort(key = lambda t: t[0], reverse = True)
pointB.sort(key = lambda t: t[0], reverse = True)
ans = 0

Bok = [True] * N

for i in range(N):
    for j in range(N):
        if Bok[j]:
            if pointR[i][0] < pointB[j][0] and pointR[i][1] < pointB[j][1]:
                ans += 1
                Bok[j] = False
                break
print(ans)

Submission status: Wrong Answer

Solution code:
import itertools

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

ans = 0
for b in blue:
    bx,by = b
    for i,r in enumerate(red):
        rx,ry = r
        if bx > rx and by > ry:
            ans += 1
            red.pop(i)
            break


print(ans)

Submission status: Wrong Answer

Solution code:
import itertools

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

ans = 0
for b in blue:
    bx,by = b
    for i,r in enumerate(red):
        rx,ry = r
        if bx > rx and by > ry:
            ans += 1
            red.pop(i)
            break


print(ans)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter

n = int(input())
R = sorted([list(map(int, input().split())) for i in range(n)], key = itemgetter(0)) 
B = sorted([list(map(int, input().split())) for _ in range(n)], key = itemgetter(0))

pair = 0
reg = [[-1, -1] for _ in range(n)]

for i in range(n):
    j = 0
    while j < n:
        diff = True
        if R[i][0] < B[j][0] and R[i][1] < B[j][1]:
            for k in range(n):
                if B[j] == reg[k]:
                    diff = False
            if diff:    
                if reg[i] == [-1, -1]:
                   reg[i] = B[j]
                elif reg[i][0] == B[j][0] and reg[0][1] > B[j][0]:
                   reg[i] == B[j]
        j += 1

for i in range(n):
    if reg[i] != [-1, -1]:
        pair += 1
    
print(pair)

Submission status: Wrong Answer

Solution code:

import bisect

NIL = -1

N = int(input())
A = [NIL] * 201

for i in range(N):
    nums=list(map(int, input().split())) 
    A[nums[0]] = nums[1]

B = [NIL] *201

for i in range(N):
    nums=list(map(int, input().split())) 
    B[nums[0]] = nums[1]
numA = len(A) - 1
numB = len(B) - 1
cnt = 0
for i in range(N):
    
    while numA >= 0:
        if A[numA] != NIL:
            
            while numB > numA:
                if B[numB] > A[numA]:
                    cnt += 1
                    A[numA] = NIL
                    B[numB] = NIL
                    break
                numB -= 1
        numA -= 1
        numB = len(B) - 1
print(cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
ab = [list(map(int, input().split(' '))) for i in range(n)]
cd = [list(map(int, input().split(' '))) for i in range(n)]
pq = [[] for i in range(n+1)]
qp = [[] for i in range(n+1)]
for q,[c,d] in enumerate(cd):
    for p,[a,b] in enumerate(ab):
        if c>a and d>b:
            pq[p+1].append(q+1)
            qp[q+1].append(p+1)
used = [0]*(n+1)
ans = 0
while True:
    for i in range(1,n+1):
        if len(pq[i]) == 1:
            ans += 1
            s = pq[i][0]
            for j in qp[s]:
                pq[j].remove(s)
            break
    else:
        break
for i in range(n):
    if pq[i] != []:
        for j in pq[i]:
            if used[j] != 1:
                used[j] = 1
                ans += 1
                break
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
ab = [list(map(int, input().split(' '))) for i in range(n)]
cd = [list(map(int, input().split(' '))) for i in range(n)]
pq = [[] for i in range(n+1)]
qp = [[] for i in range(n+1)]
for q,[c,d] in enumerate(cd):
    for p,[a,b] in enumerate(ab):
        if c>a and d>b:
            pq[p+1].append(q+1)
            qp[q+1].append(p+1)
#pq.sort(key=len)
used = [0]*(n+1)
ans = 0
while True:
    for i in range(1,n+1):
        if len(pq[i]) == 1:
            ans += 1
            s = pq[i][0]
            for j in qp[s]:
                pq[j].remove(s)
            break
    else:
        break

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
ab = [list(map(int, input().split(' '))) for i in range(n)]
cd = [list(map(int, input().split(' '))) for i in range(n)]
crs = [[] for i in range(n)]
for q,[c,d] in enumerate(cd):
    for p,[a,b] in enumerate(ab):
        if c>a and d>b:
            crs[p].append(q+1)
crs.sort(key=len)
used = [0]*(n+1)
ans = 0
for i in range(n):
    if crs[i] != []:
        for j in crs[i]:
            if used[j] != 1:
                used[j] = 1
                ans += 1
                break
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
ab = [list(map(int, input().split(' '))) for i in range(n)]
cd = [list(map(int, input().split(' '))) for i in range(n)]
doneab = []
donecd = []
for q,[c,d] in enumerate(cd):
    for p,[a,b] in enumerate(ab):
        if c>a and d>b:
            if p not in doneab:
                doneab.append(p)
            if q not in donecd:
                donecd.append(q)
print(min(len(doneab),len(donecd)))

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    N = I()
    red = []
    blue = []
    for _ in range(N):
        x, y = LI()
        red.append((x, y))
    for _ in range(N):
        x, y = LI()
        blue.append((x, y))
    red = sorted(red, key=lambda x: x[0])
    blue = sorted(blue, key=lambda x: x[1])
    blue_used = set()
    cnt = 0
    for rx, ry in red:
        for i, (bx, by) in enumerate(blue):
            if i in blue_used:
                continue
            if bx <= rx or by <= ry:
                continue
            cnt += 1
            blue_used.add(i)
            break
    print(cnt)
main()

Submission status: Wrong Answer

Solution code:
import sys
import bisect
r = sys.stdin.readline
N = int(r())
red = []
blue = []
for i in range(N):
    a, b = list(map(int, r().split()))
    red.append([a, b])
for i in range(N):
    c, d = list(map(int, r().split()))
    blue.append([c, d])

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

yred = sorted(red, key=lambda y: -y[1])
yblue = sorted(blue, key=lambda y: y[1])

i = 0
j = 0
ii = [True for i in range(2*N+1)]
jj = [True for i in range(2*N+1)]
xans = 0
for i in range(N):
    for j in range(N):
        if ii[i] and jj[j] and xred[i][0] < xblue[j][0] and xred[i][1] < xblue[j][1]:
            ii[i] = False
            jj[j] = False
            xans += 1
            break

i = 0
j = 0
ii = [True for i in range(2*N+1)]
jj = [True for i in range(2*N+1)]
yans = 0
for i in range(N):
    for j in range(N):
        if ii[i] and jj[j] and yred[i][0] < yblue[j][0] and yred[i][1] < yblue[j][1]:
            ii[i] = False
            jj[j] = False
            yans += 1
            break

print(max(xans, yans))

Submission status: Wrong Answer

Solution code:
import sys
import bisect
r = sys.stdin.readline
N = int(r())
red = []
blue = []
for i in range(N):
    a, b = list(map(int, r().split()))
    red.append([a, b])
for i in range(N):
    c, d = list(map(int, r().split()))
    blue.append([c, d])

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

yred = sorted(red, key=lambda y: -y[1])
yblue = sorted(blue, key=lambda y: -y[1])

i = 0
j = 0
ii = [True for i in range(2*N+1)]
jj = [True for i in range(2*N+1)]
xans = 0
for i in range(N):
    for j in range(N):
        if ii[i] and jj[j] and xred[i][0] < xblue[j][0] and xred[i][1] < xblue[j][1]:
            ii[i] = False
            jj[j] = False
            xans += 1
            break

i = 0
j = 0
ii = [True for i in range(2*N+1)]
jj = [True for i in range(2*N+1)]
yans = 0
for i in range(N):
    for j in range(N):
        if ii[i] and jj[j] and yred[i][0] < yblue[j][0] and yred[i][1] < yblue[j][1]:
            ii[i] = False
            jj[j] = False
            yans += 1
            break

print(max(xans, yans))

Submission status: Wrong Answer

Solution code:
import sys
import bisect
r = sys.stdin.readline
N = int(r())
red = []
blue = []
for i in range(N):
    a, b = list(map(int, r().split()))
    red.append([a, b])
for i in range(N):
    c, d = list(map(int, r().split()))
    blue.append([c, d])

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

yred = sorted(red, key=lambda y: -y[0])
yblue = sorted(blue, key=lambda y: -y[0])

i = 0
j = 0
ii = [True for i in range(2*N+1)]
jj = [True for i in range(2*N+1)]
xans = 0
for i in range(N):
    for j in range(N):
        if ii[i] and jj[j] and xred[i][0] < xblue[j][0] and xred[i][1] < xblue[j][1]:
            ii[i] = False
            jj[j] = False
            xans += 1
            break

i = 0
j = 0
ii = [True for i in range(2*N+1)]
jj = [True for i in range(2*N+1)]
yans = 0
for i in range(N):
    for j in range(N):
        if ii[i] and jj[j] and yred[i][0] < yblue[j][0] and yred[i][1] < yblue[j][1]:
            ii[i] = False
            jj[j] = False
            yans += 1
            break

print(max(xans, yans))

Submission status: Wrong Answer

Solution code:
N = int(input())
a = [list(map(int, input().split())) for _ in range(N)]
c = [list(map(int, input().split())) for _ in range(N)]
a.sort(key=lambda x: (x[0], x[1]))
c.sort(key=lambda x: (x[0], x[1]))
cnt = 0

for i in range(N):
    tmp = 10 ** 9
    index = 0
    for j in range(len(c)):
        if a[i][0] >= c[j][0] or a[i][1] >= c[j][1]:
            continue
        if a[i][0] < c[j][0] and a[i][1] < c[j][1]:
            if tmp >= c[j][1]:
                tmp = c[j][1]
                index = j
    if tmp != 10 ** 9:
        cnt += 1
        c.pop(index)

print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = [list(map(int, input().split())) for _ in range(N)]
c = [list(map(int, input().split())) for _ in range(N)]
a.sort(key=lambda x: (x[0], x[1]))
c.sort(key=lambda x: (x[0], x[1]))
cnt = 0

print(cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
ab = []
cd = []
for i in range(n):
  a, b = map(int, input().split())
  ab.append([a, b])
for j in range(n):
  c, d = map(int, input().split())
  cd.append([c, d])
cd.sort()
ans = 0
for c, d in cd:
  for i in range(n):
    if ab[i][0] < c and ab[i][1] < d:
      ans += 1
      ab[i] = [201, 201]
  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)]
blue.sort()
cnt = 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]:
            red[i][0] = 0
            red[i][1] = 0
            blue[j][0] = 0
            blue[j][1] = 0
            cnt += 1
            break
print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
red = [list(map(int, input().split())) for _ in range(N)]
blue = [list(map(int, input().split())) for _ in range(N)]
red.sort(key=lambda x: x[0], reverse=True)
blue.sort(key=lambda x: x[0], reverse=True)
cnt = 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]:
            red[i][0] = 0
            red[i][1] = 0
            blue[j][0] = 0
            blue[j][1] = 0
            cnt += 1
            break
print(cnt)