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:
from sys import stdout
printn = lambda x: stdout.write(str(x))
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 999999999
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

n = inn()
ab = []
cd = []
for i in range(n):
    ab.append(inl())
for i in range(n):
    cd.append(inl())
conn = [ [0]*n for i in range(n) ]
for i in range(n):
    for j in range(n):
        if ab[i][0]<cd[j][0] and \
           ab[i][1]<cd[j][1]:
            conn[i][j] = 1
cnt = 0
while True:
    mn = BIG
    mni = mnj = -1
    for i in range(n):
        s = sum(conn[i])
        if s==0:
            continue
        if s<mn:
            mn = s
            mni = i
            mnj = -1
    for j in range(n):
        s = sum([conn[i][j] for i in range(n)])
        if s==0:
            continue
        if s<mn:
            mn = s
            mni = -1
            mnj = j
    if mn==BIG:
        break
    cnt += 1
    if mni == -1:
        j = mnj
        for i in range(n):
            if conn[i][j]==1:
                break
    else:
        i = mni
        for j in range(n):
            if conn[i][j]==1:
                break
    for k in range(n):
        conn[i][k] = conn[k][j] = 0
print(cnt)

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

#距離が最も近いものをペアにする
D=[((b[0]-r[0])*(b[0]-r[0]) + (b[1]-r[1])*(b[1]-r[1]),i,j) for i,r in enumerate(RED) for j,b in enumerate(BLUE) if r[0]<b[0] and r[1]<b[1]]
D.sort()

#print(D)
r_used=[False]*N
b_used=[False]*N

ans=0
for d in D:
    distance,i,j=d
    if r_used[i] or b_used[j]: continue
    ans+=1
    r_used[i]=b_used[j]=True

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

#距離が最も近いものをペアにする
D=[(b[0]-r[0] + (b[1]-r[1])*2,i,j) for i,r in enumerate(RED) for j,b in enumerate(BLUE) if r[0]<b[0] and r[1]<b[1]]
D.sort()

#print(D)
r_used=[False]*N
b_used=[False]*N

ans=0
for d in D:
    distance,i,j=d
    if r_used[i] or b_used[j]: continue
    ans+=1
    r_used[i]=b_used[j]=True

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

#距離が最も近いものをペアにする
D=[(b[0]-r[0] + b[1]-r[1],i,j) for i,r in enumerate(RED) for j,b in enumerate(BLUE) if r[0]<b[0] and r[1]<b[1]]
D.sort()

#print(D)
r_used=[False]*N
b_used=[False]*N

ans=0
for d in D:
    distance,i,j=d
    if r_used[i] or b_used[j]: continue
    ans+=1
    r_used[i]=b_used[j]=True

print(ans)

Submission status: Wrong Answer

Solution code:
# input = sys.stdin.readline
from bisect import *
from collections import *
from heapq import *
# import functools
# import itertools
# import math

N=int(input())
AB=sorted([list(map(int,input().split())) for i in range(N)],key=lambda x:x[1])
CD=sorted([list(map(int,input().split())) for i in range(N)],key=lambda x:x[1])
count=0
for c,d in CD:
    tmp=[[AB[i][0],i] for i in range(len(AB)) if AB[i][0]<c and AB[i][1]<d]
    if tmp:
        idx=tmp[0][1]
        _max=tmp[0][0]
        for a,i in tmp:
            if a>_max:
                _max=a
                idx=i
        AB.pop(i)
        count+=1
print(count)

Submission status: Wrong Answer

Solution code:
N=int(input())

red=[]
for _ in range(N):
    a,b=map(int,input().split())
    red.append([a,b])
red.sort(key=lambda x:x[1])
red.sort(key=lambda x:x[0])

blue=[]
for _ in range(N):
    c,d=map(int,input().split())
    blue.append([c,d])
blue.sort(key=lambda x:x[1])
blue.sort(key=lambda x:x[0])


ans=0
for b in blue[::-1]:
    for index,r in enumerate(red[::-1]):
        #print(b,r,index)
        if b[0]>r[0] and b[1]>r[1]:
            red[N-1-index]=[10**9,10**9]
            ans+=1
            break


#print(red)
#print(blue)
print(ans)

Submission status: Wrong Answer

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

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

ans = 0

for r in R:
    for i, b in enumerate(B):
        if i in used:
            continue
        if r < b:
            ans += 1
            used.add(i)
            break

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

N = int(input())
AB = [list(map(int, input().split())) for _ in range(N)]
CD = [[list(map(int, input().split())), [], 0] for _ in range(N)]

for i in range(N):
  C, D = CD[i][0]
  for j in range(N):
    A, B = AB[j]
    if C > A and D > B:
      CD[i][1].append(AB[j])
for i in range(N):
  CD[i][2] = len(CD[i][1])
CD.sort(key = lambda x: x[2])

d = defaultdict(int)
for A, B in AB:
  d[A] = 1
#print(d)

answer = 0
for i in range(N):
  for j in range(CD[i][2]):
    if d[CD[i][1][j][0]] == 1:
      answer += 1
      d[CD[i][1][j][0]] = 0
      break
print(answer)

Submission status: Wrong Answer

Solution code:
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations,combinations
import sys
import bisect
import string
import math
import time
#import random
def I():
    return int(input())
def MI():
    return map(int,input().split())
def LI():
    return [int(i) for i in input().split()]
def LI_():
    return [int(i)-1 for i in input().split()]
def StoI():
    return [ord(i)-97 for i in input()]
def ItoS(nn):
    return chr(nn+97)
def GI(V,E,Directed=False,index=0):
    org_inp=[]
    g=[[] for i in range(n)]
    for i in range(E):
        inp=LI()
        org_inp.append(inp)
        if index==0:
            inp[0]-=1
            inp[1]-=1
        if len(inp)==2:
            a,b=inp
            g[a].append(b)
            if not Directed:
                g[b].append(a)
        elif len(inp)==3:
            a,b,c=inp
            aa=(inp[0],inp[2])
            bb=(inp[1],inp[2])
            g[a].append(bb)
            if not Directed:
                g[b].append(aa)
    return g,org_inp
def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end)
YN=['Yes','No']
mo=10**9+7
inf=float('inf')
l_alp=string.ascii_lowercase
u_alp=string.ascii_uppercase

#sys.setrecursionlimit(10**5)
input=lambda: sys.stdin.readline().rstrip()

show_flg=False
show_flg=True

n=I()
R=[]
B=[]

for i in range(n):
    a,b=LI()
    R.append((a,b))

for i in range(n):
    a,b=LI()
    B.append((a,b))

RR=[]
B.sort(key=lambda x:x[0])
R.sort(key=lambda x:-x[0])
ans=0

for c,d in B:
    while R and R[-1][0]<c:
        RR.append(R.pop())
    
    R.sort(key=lambda x:-x[1])
    for a,b in RR:
        if a<c and b<d:
            ans+=1
            RR.remove((a,b))
            break
        
print(ans)

Submission status: Wrong Answer

Solution code:
# Dinic's algorithm
from collections import deque
class Dinic:
    def __init__(self, N):
        self.N = N
        self.G = [[] for i in range(N)]

    def add_edge(self, fr, to, cap):
        forward = [to, cap, None]#(行き先、容量、逆辺の参照)
        forward[2] = backward = [fr, 0, forward]
        self.G[fr].append(forward)
        self.G[to].append(backward)

    def add_multi_edge(self, v1, v2, cap1, cap2):
        edge1 = [v2, cap1, None]
        edge1[2] = edge2 = [v1, cap2, edge1]
        self.G[v1].append(edge1)
        self.G[v2].append(edge2)

    def bfs(self, s, t):
        self.level = level = [None]*self.N
        deq = deque([s])
        level[s] = 0
        G = self.G
        while deq:
            v = deq.popleft()
            lv = level[v] + 1
            for w, cap, _ in G[v]:
                if cap and level[w] is None:
                    level[w] = lv
                    deq.append(w)
        return level[t] is not None

    def dfs(self, v, t, f):
        if v == t:
            return f
        level = self.level
        for e in self.it[v]:
            w, cap, rev = e
            if cap and level[v] < level[w]:
                d = self.dfs(w, t, min(f, cap))
                if d:
                    e[1] -= d
                    rev[1] += d
                    return d
        return 0

    def flow(self, s, t):
        flow = 0
        INF = 10**9 + 7
        G = self.G
        while self.bfs(s, t):
            *self.it, = map(iter, self.G)
            f = INF
            while f:
                f = self.dfs(s, t, INF)
                flow += f
        return flow
N = int(input())
D = Dinic(N*2+2)
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))
for i in range(N):
    D.add_edge(0, i+1, 1)
    D.add_edge(i+1+N, N*2+1, 1)
    for j in range(N):
        a, b = red[i]
        c, d = blue[i]
        if a<c and b<d:
            D.add_edge(i+1, j+1+N, 1)
print(D.flow(0, N*2+1))

Submission status: Wrong Answer

Solution code:
N=int(input())
#赤の点
Red=[[int(s) for s in input().split()] for _ in range(N)]
Blue=[[int(s) for s in input().split()] for _ in range(N)]

#x座標が小さい順->y座標が大きい順にソート
Red =sorted(Red ,key=lambda x:(x[0],-x[1]))
Blue=sorted(Blue,key=lambda x:(x[0],-x[1]))

ans=0
for x,y in Blue:
  for i,point in enumerate(Red):
    a,b=point
    if a<x and b<y:
      ans+=1
      del Red[i]
      break
    if a>=x:
      break
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
  N = int(input())
  ab = [list(map(int,input().split())) for _ in range(N)]
  cd = [list(map(int,input().split())) for _ in range(N)]
  ab = sorted(ab)
  cd = sorted(cd)
  cnt = 0
  i = 0
  while i < len(cd):
    x = cd[i][0]
    std = -1
    y = -1
    for j in range(len(ab)):
      if ab[j][0] < x and ab[j][1] > y:
        std = j
        y = ab[j][1]
    if std == -1:
      i += 1
      continue
    cd.pop(i)
    ab.pop(std)
    cnt += 1
  print(cnt)
main()

Submission status: Wrong Answer

Solution code:
def find_most_rightup(c,d):
  tmpA = []
  for i in range(len(AB)):
    a,b = AB[i]
    if a<c and b<d:
      tmpA.append([b,i])
  if len(tmpA) > 0:
    return sorted(tmpA, reverse=True)[0][1]
  else: return None

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

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

AB.sort(reverse=True)
CD.sort()
ans = 0
for dis, c,d in CD:
  min_i = find_most_rightup(c,d)
  if min_i is not None:
    del AB[min_i]
    ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
def find_most_rightup(c,d):
  min_disx, min_disy = float('inf'), float('inf')
  min_i = None
  
  for i in range(len(AB)):
    a,b = AB[i]
    if a<c and b<d:
      if min_disx > (c-a):
        min_disx = c-a
        min_disy = d-b
        min_i = i
      elif  min_disx > (c-a) and min_disy > (d-b):
        min_disx = c-a
        min_disy = d-b
        min_i = i
  return min_i

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

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

AB.sort(reverse=True)
CD.sort()
ans = 0
for dis, c,d in CD:
  min_i = find_most_rightup(c,d)
  if min_i is not None:
    del AB[min_i]
    ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
def find_most_rightup(c,d):
  min_dis = float('inf')
  min_i = None
  for i in range(len(AB)):
    a,b = AB[i]
    if a<c and b<d:
      dis = (c-a) + (d-b)
      if min_dis > dis:
        min_dis = dis
        min_i = i
  return min_dis, min_i

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

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

AB.sort(reverse=True)
CD.sort()
ans = 0
for dis, c,d in CD:
  min_dis, min_i = find_most_rightup(c,d)
  if min_i is not None:
    del AB[min_i]
    ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
def find_most_rightup(c,d):
  min_dis = float('inf')
  min_i = None
  for i in range(len(AB)):
    a,b = AB[i]
    if a<c and b<d:
      dis = a + b
      if min_dis > dis:
        min_dis = dis
        min_i = i
  return min_dis, min_i

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

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

AB.sort(reverse=True)
CD.sort()
ans = 0
for dis, c,d in CD:
  min_dis, min_i = find_most_rightup(c,d)
  if min_i is not None:
    del AB[min_i]
    ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
def find_most_rightup(c,d):
  min_dis = float('inf')
  min_i = None
  for i in range(len(AB)):
    a,b = AB[i]
    if a<c and b<d:
      dis = (c-a) + (d-b)
      if min_dis > dis:
        min_dis = dis
        min_i = i
  return min_dis, min_i

N = int(input())
AB = [list(map(int,input().split())) for _ in range(N)]
CD = [list(map(int,input().split())) for _ in range(N)]
CD.sort()
ans = 0
for c,d in CD:
  min_dis, min_i = find_most_rightup(c,d)
  if min_i is not None:
    del AB[min_i]
    ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
def find_most_rightup(c,d):
  for i in range(len(AB)):
    dis, a,b = AB[i]
    if a<c and b<d:
      return i
  return None

N = int(input())

AB = []
for _ in range(N):
  a,b = map(int,input().split())
  AB.append([-(a**2+b**2),a,b])
AB.sort()

CD = []
for _ in range(N):
  c,d = map(int,input().split())
  CD.append([c**2+d**2,c,d])
CD.sort()

ans = 0
for dis, c,d in CD:
  min_i = find_most_rightup(c,d)
  if min_i is not None:
    del AB[min_i]
    ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
def find_most_rightup(c,d):
  min_dis = float('inf')
  min_i = None
  for i in range(len(AB)):
    a,b = AB[i]
    if a<c and b<d:
      dis = ((a-c)**2+(b-d)**2)**.5
      if min_dis > dis:
        min_dis = dis
        min_i = i
  return min_dis, min_i

N = int(input())
AB = [list(map(int,input().split())) for _ in range(N)]
CD = [list(map(int,input().split())) for _ in range(N)]
CD.sort()
ans = 0
for c,d in CD:
  min_dis, min_i = find_most_rightup(c,d)
  if min_i is not None:
    del AB[min_i]
    ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
def find_most_rightup(c,d):
  min_dis = float('inf')
  min_i = None
  for i in range(len(AB)):
    a,b = AB[i]
    if a<c and b<d:
      dis = ((a-c)**2+(b-d)**2)**.5
      if min_dis > dis:
        min_dis = dis
        min_i = i
  return min_dis, min_i

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

CD = []
for _ in range(N):
  c,d = map(int,input().split())
  CD.append([c**2+d**2,c,d])
CD.sort()

ans = 0
for dis, c,d in CD:
  min_dis, min_i = find_most_rightup(c,d)
  if min_i is not None:
    del AB[min_i]
    ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
def find_most_rightup(c,d):
  min_dis = float('inf')
  min_i = None
  for i in range(len(AB)):
    a,b = AB[i]
    if a<c and b<d:
      dis = ((a-c)**2+(b-d)**2)**.5
      if min_dis > dis:
        min_dis = dis
        min_i = i
  return min_dis, min_i

N = int(input())
AB = [list(map(int,input().split())) for _ in range(N)]
CD = [list(map(int,input().split())) for _ in range(N)]
ans = 0
for c,d in CD:
  min_dis, min_i = find_most_rightup(c,d)
  if min_i is not None:
    del AB[min_i]
    ans += 1
print(ans)

Submission status: Wrong Answer

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

cnt = 0
sCD = sorted(CD, key=lambda x: x[1])
for c, d in sCD:
  AB = sorted(AB, key=lambda x: x[0])
#  print(AB)
  for itr in range(len(AB)):
    a, b = AB[itr]
    if a < c and b < d:
      cnt += 1
      AB.pop(itr)
      break
print(cnt)

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    Red = []
    Blue = []
    for i in range(N):
        a, b = map(int, input().split())
        Red.append([b,a])
    for i in range(N):
        c, d = map(int, input().split())
        Blue.append([c,d])

    Red.sort()
    Blue.sort()
    ans = 0
    for x, y in Blue:
        for v, u in Red:
            if x > u and y > v:
                ans += 1
                Red.remove([v,u])
                break
    
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    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([d,c])

    Red.sort()
    Blue.sort()
    ans = 0
    for x, y in Blue:
        for v, u in Red:
            if x > u and y > v:
                ans += 1
                Red.remove([v,u])
                break
    
    print(ans)

if __name__ == "__main__":
    main()

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)]
cd.sort()
count=0
for i in range(n):
    c,d=cd[i]
    m=-1
    memo=-1
    for j in range(len(ab)):
        a,b=ab[j]
        if a<c and m<b:
            memo=j
            m=b
    if memo!=-1:
        ab.pop(memo)
        count+=1
print(count)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left,bisect_right
import sys
def input(): return sys.stdin.readline().strip()

def main(bisect_left=bisect_left, bisect_right=bisect_right):
    n=int(input())
    aa = []
    for _ in range(n):
        a,b=map(int,input().split())
        aa.append((a,b))
    cc = []
    for _ in range(n):
        c,d=map(int,input().split())
        cc.append((c,d))
    aa = sorted(aa, reverse=True)
    cc = sorted(cc)
    cnt = 0
    for a in aa:
        for c in cc:
            if a < c:
                cnt += 1
                cc.remove(c)
                break
    print(cnt)

main()

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left,bisect_right
import sys
def input(): return sys.stdin.readline().strip()

def main(bisect_left=bisect_left, bisect_right=bisect_right):
    n=int(input())
    aa = []
    for _ in range(n):
        a,b=map(int,input().split())
        aa.append((a,b))
    cc = []
    for _ in range(n):
        c,d=map(int,input().split())
        cc.append((c,d))
    aa = sorted(aa)
    cc = sorted(cc)
    cnt = 0
    for a in aa:
        for c in cc:
            if a < c:
                cnt += 1
                cc.remove(c)
                break
    print(cnt)

main()

Submission status: Wrong Answer

Solution code:
import sys
from operator import itemgetter
input = sys.stdin.readline

def main():
    N = int(input())
    red = [list(map(int, input().split())) for _ in range(N)]
    blue = [list(map(int, input().split())) for _ in range(N)]
    red = sorted(red, key=itemgetter(1), reverse=True)
    blue = sorted(blue, key=itemgetter(1))
    visited = [False] * N
    ans = 0
    for i in blue:
        c = i[0]
        d = i[1]
        for j in range(N):
            a = red[j][0]
            b = red[j][1]
            if a < c and b < d and not visited[j]:
                ans += 1
                visited[j] = True
                break
    print(ans)


if __name__ == '__main__': main()

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()
B.sort()

ans = 0
BS = [False for _ in range(N)]
for rx,ry in R:
  pi = -1
  minxy = 2*N+1
  for i in range(N):
    if not BS[i]:
      bx,by = B[i]
      if rx < bx and ry < by and minxy > min(bx-rx,by-ry):
        pi = i
        minxy = min(bx-rx,by-ry)
  if pi >= 0:
    ans += 1
    BS[pi] = True
print(ans)

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()
B.sort()

ans = 0
BS = [False for _ in range(N)]
for rx,ry in R:
  for i in range(N):
    if not BS[i]:
      bx,by = B[i]
      if rx < bx and ry < by:
        ans += 1
        BS[i] = True
        break
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:(x[0],x[1]), reverse=True)
BLUE.sort(key=lambda x:(x[0],x[1]), reverse=True)
#print(RED)
#print(BLUE)

ans = 0
i = 0
j = 0
while(i<N and j<N):
  if BLUE[i][0] > RED[j][0] and BLUE[i][1] > RED[j][1]:
    ans += 1
    i += 1
  j += 1
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:(x[0],x[1]), reverse=True)
BLUE.sort(key=lambda x:(x[0],x[1]), reverse=True)
#print(RED)
#print(BLUE)

ans = 0
i = 0
j = 0
while(i<N and j<N):
  if BLUE[i][0] > RED[j][0]:
    ans += 1
    i += 1
  j += 1
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)]

def solve(reds, blues):
    res = 0
    r_idx = 0
    b_idx = 0

    while r_idx < N and b_idx < N:
        r = reds[r_idx]
        b = blues[b_idx]

        if r[0] < b[0] and r[1] < b[1]:
            res += 1
            r_idx += 1
            b_idx += 1
        else:
            r_idx += 1
    return res


R.sort(key=lambda x: (x[0], x[1]), reverse=True)
B.sort(key=lambda x: (x[0], x[1]), reverse=True)
res = solve(R, B)
R.sort(key=lambda x: (x[1], x[0]), reverse=True)
B.sort(key=lambda x: (x[1], x[0]), reverse=True)
res = max(res, solve(R, B))

print(res)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
N=int(input())
A=[]
B=[]

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

A.sort()
B.sort()

count=0
while len(B):
    b=B.pop(0)
    #print(b)
    pair=[0,0]
    judge=False
    for i in range(len(A)):
        if b[0]>A[i][0] and b[1]>A[i][1]:#条件をみたしたのを選ぶ
            judge=True
            if A[pair[0]][1]<=A[i][1]:
                pair[0]=i
    if judge:
        count+=1
        #print(A[pair[0]])
        A.pop(pair[0])            
    
print(count)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
N=int(input())
A=[]
B=[]

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

A.sort()
B.sort()

count=0
while len(B):
    b=B.pop(0)
    pair=[0,0]
    judge=False
    for i in range(len(A)):
        if b[0]>=A[i][0] and b[1]>=A[i][1]:#条件をみたしたのを選ぶ
            judge=True
            if A[pair[0]][1]<=A[i][1]:
                pair[0]=i
    if judge:
        count+=1
        A.pop(pair[0])            
    
print(count)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
N=int(input())
A=[]
B=[]

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

A.sort()
B.sort()

count=0
while len(B):
    b=B.pop(0)
    pair=[0,0]
    judge=False
    for i in range(len(A)):
        if b[0]>=A[i][0] and b[1]>=A[i][1]:#条件をみたしたのを選ぶ
            judge=True
            if A[pair[0]][1]<A[i][1]:
                pair[0]=i
    if judge:
        count+=1
        A.pop(pair[0])            
    
print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
ab = [[0, 0] for i in range(N)]
b = [0]*N
cd = [[0, 0] for i in range(N)]
d = [0]*N

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

points2 = [[] for i in range(N)]
ab.sort(key=lambda x: x[0])
ab.sort(key=lambda x: x[1])

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

points2.sort(key=lambda x: len(x))
ans = 0

for i in range(N):
    if len(points2[i]) == 0:
        continue
    for j in range(i+1, N):
        if points2[i][0] in points2[j]:
            points2[j].pop(points2[j].index(points2[i][0]))
    ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
ab = [[0, 0] for i in range(N)]
cd = [[0, 0] for i in range(N)]

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

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

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

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

points.sort(key=lambda x: len(x))
ans = 0
for i in range(N):
    if len(points[i]) == 0:
        continue
    for j in range(i+1, N):
        if points[i][0] in points[j]:
            points[j].pop(points[j].index(points[i][0]))
    ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
ab = [[0, 0] for i in range(N)]
cd = [[0, 0] for i in range(N)]

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

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

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

points.sort(key=lambda x: len(x))
ans = 0
for i in range(N):
    if len(points[i]) == 0:
        continue
    for j in range(i+1, N):
        if points[i][0] in points[j]:
            points[j].pop(points[j].index(points[i][0]))
    ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
ab=[]
for i in range(N):
  ab.append(list(map(int,input().split())))
cd=[]
for i in range(N):
  cd.append(list(map(int,input().split())))
  
#print(ab)
#print(cd)

g=[[0 for _ in range(N)] for _ in range(N)]
for i in range(N):
  for j in range(N):
    if cd[j][0]>ab[i][0] and cd[j][1]>ab[i][1]:
      g[i][j]+=1

for i in range(N):
  g[i].append(sum(g[i]))
#print(g)

g.sort(key=lambda x: x[N])
#print(g)

ans=0
for i in range(N):
  if g[i][N]>0:
    for j in range(N):
      if g[i][j]==1:
        ans+=1
        for k in range(N):
          g[k][j]=0
        break
  #print(g)
print(ans)

Submission status: Wrong Answer

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

ab_list.sort(reverse=True)
cd_list.sort(reverse=True)

count = 0

for cd in cd_list:
  for ab in ab_list:  
    if cd[0] > ab[0] and cd[1] > ab[1]:
      count += 1
      ab_list.remove(ab)
      break

print(count)

Submission status: Wrong Answer

Solution code:
# ARC092C - 2D Plane 2N Points (ABC091C)
# greedy algorithm
def main():
    N = int(input())
    A = sorted(
        [tuple(map(int, input().split())) for _ in range(N)],
        key=lambda x: x[1],
        reverse=1,
    )
    B = sorted([tuple(map(int, input().split())) for _ in range(N)])
    ans, memo = 0, set()
    for bx, by in B:
        for i, (ax, ay) in enumerate(A):
            if i not in memo and ax < bx and ay < by:
                ans += 1
                memo |= {i}
    print(ans)


if __name__ == "__main__":
    main()

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 val:val[1], reverse=True)
b.sort()

ans = 0

for bb in b:
    for i in range(N):
        if bb[0] > r[i][0]:
            ans += 1
            N -= 1
            r.pop(i)
            break

print(ans)

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 val:val[1], reverse=True)
b.sort()

ans = 0

for bb in b:
    for i in range(N):
        if bb[0] > r[i][0]:
            ans += 1
            N -= 1
            r.pop(i)
            break

print(ans)
print(r)
print(b)

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 val:val[1], reverse=True)
b.sort(reverse=True)

ans = 0

for bb in b:
    for i in range(N):
        if bb[1] > r[i][1]:
            ans += 1
            N -= 1
            r.pop(i)
            break

print(ans)

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 val:val[1], reverse=True)
b.sort(reverse=True)

ans = 0

for bb in b:
    for i in range(N):
        if bb[0] > r[i][0]:
            ans += 1
            N -= 1
            r.pop(i)
            break

print(ans)

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(reverse=True)
b.sort(key=lambda val:val[1], reverse=True)

ans = 0

for rr in r:
    for i in range(N):
        if rr[0] < b[i][0]:
            ans += 1
            N -= 1
            b.pop(i)
            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)]
B.sort(key = lambda x:x[0])
R.sort(key = lambda x:x[1], reverse = True)

print(R)
ans = 0
for bx,by in B:
    print(bx,by)
    for i in range(len(R)):
        if R[i][0] < bx and R[i][1] < by:
            print(R[i],"とマッチ")
            del R[i]
            ans += 1
            break
print(ans)