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:
"""ABC091 2D Plane 2N Points diff:
"""

N = int(input())

ab = [tuple(map(int, input().split())) for _ in range(N)]
cd = [tuple(map(int, input().split())) for _ in range(N)]

ans_x = 0
cd.sort(key=lambda x: x[0])
ab.sort(key=lambda x: x[0], reverse=True)
ab_used = [0]*N
for i, (c, d) in enumerate(cd):
    for j, (a, b) in enumerate(ab):
        if not ab_used[j] and a < c and b < d:
            ab_used[j] = 1
            ans_x += 1
            break

ans_y = 0
cd.sort(key=lambda x: x[1])
ab.sort(key=lambda x: x[1], reverse=True)
ab_used = [0]*N
for i, (c, d) in enumerate(cd):
    for j, (a, b) in enumerate(ab):
        if not ab_used[j] and a < c and b < d:
            ab_used[j] = 1
            ans_y += 1
            break

print(max(ans_x, ans_y))

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

ans_x = 0
cd.sort(key=lambda x: x[0])
ab.sort(key=lambda x: x[0])
ab_used = [0]*N
for i, (c, d) in enumerate(cd):
    for j, (a, b) in enumerate(ab):
        if not ab_used[j] and a < c and b < d:
            ab_used[j] = 1
            ans_x += 1
            break

ans_y = 0
cd.sort(key=lambda x: x[1])
ab.sort(key=lambda x: x[1])
ab_used = [0]*N
for i, (c, d) in enumerate(cd):
    for j, (a, b) in enumerate(ab):
        if not ab_used[j] and a < c and b < d:
            ab_used[j] = 1
            ans_y += 1
            break
print(max(ans_x, ans_y))

Submission status: Wrong Answer

Solution code:
N = int(input())
X = [0]*(2*N)
Y = [0]*(2*N)

for _ in range(N):
  a, b = map(int, input().split())
  X[a] += 1
  Y[b] += 1

for _ in range(N):
  c, d = map(int, input().split())
  X[c] -= 1
  Y[d] -= 1

ans1, ans2 = 0, 0
temp1, temp2 = 0, 0

for i in range(2*N):
  if X[i] == 1:
    temp1 += 1
  else:
    if temp1 > 0:
      temp1 -= 1
      ans1 += 1
  if Y[i] == 1:
    temp2 += 1
  else:
    if temp2 > 0:
      temp2 -= 1
      ans2 += 1

print(min(ans1, ans2))

Submission status: Wrong Answer

Solution code:
N = int(input())
X = [0]*(2*N)
Y = [0]*(2*N)

for _ in range(N):
  a, b = map(int, input().split())
  X[a] += 1
  Y[b] += 1

for _ in range(N):
  c, d = map(int, input().split())
  Y[c] -= 1
  Y[d] -= 1

ans1, ans2 = 0, 0
temp1, temp2 = 0, 0

for i in range(2*N):
  if X[i] == 1:
    temp1 += 1
  else:
    if temp1 > 0:
      temp1 -= 1
      ans1 += 1
  if Y[i] == 1:
    temp2 += 1
  else:
    if temp2 > 0:
      temp2 -= 1
      ans2 += 1
  
print(min(ans1, ans2))

Submission status: Wrong Answer

Solution code:
n = int(input())
red, blue = [], []
for _ in range(n):
    a, b = map(int, input().split())
    red.append([a, b, min(a, b)])
for _ in range(n):
    a, b = map(int, input().split())
    blue.append([a, b, min(a, b)])
    
red.sort(key=lambda x: x[2])
blue.sort(key=lambda x: x[2])
status = [False for _ in range(n)]
ans = 0
for i in range(n):
    for j in range(n):
        if not status[j]:
            if red[i][0] < blue[j][0] and red[i][1] < blue[j][1]:
                ans += 1
                status[j] = True
                break
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
red, blue = [], []
for _ in range(n):
    a, b = map(int, input().split())
    red.append([a, b, min(a, b)])
for _ in range(n):
    a, b = map(int, input().split())
    blue.append([a, b, min(a, b)])
    
red.sort(key=lambda x: x[2])
blue.sort(key=lambda x: x[2])
status = [False for _ in range(n)]
ans = 0
for i in range(n):
    for j in range(n):
        if not status[j]:
            if red[i][0] <= blue[j][0] and red[i][1] <= blue[j][1]:
                ans += 1
                status[j] = True
                break
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
R=[]
for _ in range(n):
  R.append(list(map(int,input().split())))
R.sort(key=lambda x:x[0])
B=[]
for _ in range(n):
  B.append(list(map(int,input().split())))
B.sort(key=lambda x:x[0])
f=[0]*n

A=[[] for _ in range(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]:
      A[i].append(j)
A.sort(key=lambda x:len(x))
f=[0]*n
ans=0
for i in range(n):
  v=A[i]
  for j in range(len(v)):
    if f[v[j]]==0:
      f[v[j]]=1
      ans+=1
      break
print(ans)

Submission status: Wrong Answer

Solution code:
with open(0) as f:
    N = int(f.readline())
    red = [tuple(map(int, f.readline().split())) for _ in range(N)]
    blue = [tuple(map(int, f.readline().split())) for _ in range(N)]

red.sort(key=max, reverse=True)
blue.sort(key=max, reverse=True)
ans = 0
for a, b in red:
    C = [(c,d) for c,d in blue if (a < c) and (b < d)]
    if len(C) == 0:
        continue
    C.sort(key=lambda X:X[1], reverse=True)
    ans += 1
    blue.remove(C[0])
print(ans)

Submission status: Wrong Answer

Solution code:
with open(0) as f:
    N = int(f.readline())
    red = [tuple(map(int, f.readline().split())) for _ in range(N)]
    blue = [tuple(map(int, f.readline().split())) for _ in range(N)]

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

Submission status: Wrong Answer

Solution code:
n = int(input())
reds = sorted([list(map(int,input().split())) for i in range(n)])
blues = sorted([list(map(int,input().split())) for i in range(n)])

reds = reds[::-1]
res = 0

for c,d in blues:
  for a,b in reds:
    if a<c and b<d:
      reds.remove([a,b])
      res+=1
      break
      
print(res)

Submission status: Wrong Answer

Solution code:
n = int(input())
reds = sorted([list(map(int,input().split())) for i in range(n)])
blues = sorted([list(map(int,input().split())) for i in range(n)])

reds.sort(reverse = True)
res = 0

for c,d in blues:
  for a,b in reds:
    if a<c and b<d:
      reds.remove([a,b])
      res+=1
      break
      
print(res)

Submission status: Wrong Answer

Solution code:
import operator
import bisect

n=int(input())
red=[tuple(map(int,input().split())) for _ in range(n)]
blue=[tuple(map(int,input().split())) for _ in range(n)]

red.sort(key=operator.itemgetter(0,1))
blue.sort(key=operator.itemgetter(0,1))
print(red)
print(blue)
count=0
for i in range(n):
  for j in reversed(range(len(red))):
    #print("j",j)
    if not red:
      break
    if red[j][0]<blue[i][0]:
      tmp=red[:j+1]
      tmp.sort(key=lambda x:x[1],reverse=True)
      for t in tmp:
        if t[1]<blue[i][1]:
          count+=1
          red.pop(red.index(t))
          print("t",t,"blue[i]",blue[i])
          break
    else:
      continue
    break

print(count)

Submission status: Wrong Answer

Solution code:
import operator
import bisect

n=int(input())
red=[tuple(map(int,input().split())) for _ in range(n)]
blue=[tuple(map(int,input().split())) for _ in range(n)]

red.sort(key=operator.itemgetter(0,1))
blue.sort(key=operator.itemgetter(0,1))
#print(red)
#print(blue)
count=0
for i in range(n):
  for j in reversed(range(len(red))):
    #print("j",j)
    if not red:
      break
    if red[j][0]<blue[i][0]:
      tmp=red[:j+1]
      tmp.sort(key=lambda x:x[1],reverse=True)
      for t in tmp:
        if t[1]<blue[i][1]:
          count+=1
          red.pop(red.index(t))
          break
  else:
    continue
  break
      #max_y_idx=red.index(max(red[:j+1],key=lambda x:x[1]))
      #print("max_y_idx",max_y_idx,red[max_y_idx],"blue[i]",blue[i])
      #print("red",red)

print(count)

Submission status: Wrong Answer

Solution code:
import operator
import bisect

n=int(input())
red=[tuple(map(int,input().split())) for _ in range(n)]
blue=[tuple(map(int,input().split())) for _ in range(n)]

red.sort(key=operator.itemgetter(0,1))
blue.sort(key=operator.itemgetter(0,1))
#print(red)
#print(blue)
count=0
for i in range(n):
  for j in reversed(range(len(red))):
    #print("j",j)
    if not red:
      break
    if red[j][0]<blue[i][0]:
      max_y_idx=red.index(max(red[:j+1],key=lambda x:x[1]))
      #print("max_y_idx",max_y_idx,red[max_y_idx],"blue[i]",blue[i])
      count+=1
      red.pop(max_y_idx)
      #print("red",red)
      break

print(count)

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

red.sort()
blue.sort()
#print(red)
#print(blue)
count=0
for i in range(n):
  flag=False
  for j in range(len(blue)):
    if red[i][0]<blue[j][0] and red[i][1]<blue[j][1]:
      #print(red[i],blue[j])
      count+=1
      blue.pop(j)
      break
print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())

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

ans=0

for b in blue:
    tmp = red.copy()
    match = []
    for t in tmp:
        if b[0] > t[0] and b[1] > t[1]:
            match.append(t)
    if match:
        ans += 1
        d = match[0]
        for m in match:
            if m[1] > d[1]:
                d = m
        red.remove(d)

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

red = []
blue = []
for _ in range(N):
    a,b = map(int,input().split())
    red.append((a,b))
red.sort()
red_desc = sorted(red,reverse=True)
for _ in range(N):
    c,d = map(int,input().split())
    blue.append((c,d))
blue.sort()
blue_desc = sorted(blue,reverse=True)

ans=ans_desc=0
for r in red:
    tmp = blue.copy()
    for t in tmp:
        if r[0] < t[0] and r[1] < t[1]:
            ans += 1
            blue.remove(t)
            break
for r in red_desc:
    tmp = blue_desc.copy()
    for t in tmp:
        if r[0] < t[0] and r[1] < t[1]:
            ans_desc += 1
            blue_desc.remove(t)
            break

print(max(ans,ans_desc))

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque
input = sys.stdin.readline

class Dinic:
    def __init__(self, v):
        self.vertice = v
        self.inf = int(1e9)
        self.graph = [[] for i in range(v)]
        self.level = [0]*v
        self.iter = [0]*v
    
    def add_edge(self, fr, to, cap):
        self.graph[fr].append([to, cap, len(self.graph[to])])
        self.graph[to].append([fr, cap, len(self.graph[fr])-1])
    
    def bfs(self, s):
        self.level = [-1]*self.vertice
        que = deque([])
        self.level[0] = s
        que.append(s)

        while que:
            v = que.popleft()
            for i in range(len(self.graph[v])):
                e = self.graph[v][i]
                if e[1] > 0 and self.level[e[0]] < 0:
                    self.level[e[0]] = self.level[v] + 1
                    que.append(e[0])
    
    def dfs(self, v, t, f):
        if v == t:
            return f
        for i in range(self.iter[v], len(self.graph[v])):
            self.iter[v] = i
            e = self.graph[v][i]
            if e[1] > 0 and self.level[v] < self.level[e[0]]:
                d = self.dfs(e[0], t, min(f, e[1]))
                if d > 0:
                    e[1] -= d
                    self.graph[e[0]][e[2]][1] += d
                    return d
        return 0
    
    def max_flow(self, s, t):
        flow = 0
        while True:
            self.bfs(s)
            if self.level[t] < 0:
                return flow
            self.iter = [0]*self.vertice

            f = 1
            while f:
                f = self.dfs(s, t, self.inf)
                if f == 0:
                    break
                flow += f
    
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)]
    
    flow = Dinic(n*2+2)
    for i in range(n):
        flow.add_edge(0, i+1, 1)
        flow.add_edge(n+i+1, 2*n+1, 1)
        for j in range(n):
            if red[i][0] < blue[j][0] and red[i][1] < blue[j][1]:
                flow.add_edge(i+1, n+j+1, 1)
    
    
    ans = flow.max_flow(0, 2*n+1)
    print(ans)
    
if __name__ == "__main__":
    main()

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

blues = []
for i in range(N):
    c, d = map(int, input().split())
    blues.append([c,d])
blues.sort()

flag = [False for i in range(N)]
ans = 0
for i in range(N):
    c, d = blues[i][0], blues[i][1]
    for j in range(N):
        if flag[j] == True:
            continue
        a, b = reds[i][0], reds[i][1]
        if c>a and d>b:
            flag[j] = True
            ans += 1
            break
print(ans)

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

blues = []
for i in range(N):
    c, d = map(int, input().split())
    blues.append([c,d])
blues.sort()

flag = [False for i in range(N)]
ans = 0
for i in range(N):
    c, d = blues[i][0], blues[i][1]
    for j in range(N):
        if flag[j] == True:
            continue
        a, b = reds[i][0], reds[i][1]
        if c>a and d>b:
            flag[j] = True
            ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    from sys import stdin
    def input():
        return stdin.readline().strip()
    
    n = int(input())
    red = [tuple(map(int, input().split())) for _ in range(n)]
    blue = [tuple(map(int, input().split())) for _ in range(n)]

    red.sort()
    blue.sort()

    now = 0
    for i in blue:
        while now < len(red) and red[now] < i:
            now += 1
        
        l = red[:now]
        if l == []:
            continue

        l = sorted(l, key=lambda x: x[1])
        if l[0][1] > i[1]:
            continue
        
        # binary search
        left = 0
        right = len(l) - 1
        while left < right:
            center = (left + right + 1) // 2
            if l[center][1] < i[1]:
                left = center
            else:
                right = center - 1

        print(l[left], i)
        red.remove(l[left])
        now -= 1

    print(n - len(red))

main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import networkx as nx
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)]


ans = 0
for i in range(n):
    for j in range(n):
        a, b = ab[i]
        c, d = cd[i]

        if a < c and b < d:
            ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
def abc091_c():
    n = int(input())
    red = []
    blue = []
    for _ in range(n):
        a, b = (int(x) for x in input().split())
        red.append((a, b))
    for _ in range(n):
        c, d = (int(x) for x in input().split())
        blue.append((c, d))
    blue = sorted(blue, key=lambda x: x[0])

    ans = 0
    r_used = [False]*n
    for c, d in blue:
        match = -1
        for i, (a, b) in enumerate(red):
            if r_used[i]: continue
            if a < c and b < d:
                if match == -1:
                    match = i
                else:
                    if red[match][1] < d: match = i
        if match != -1:
            ans += 1
            r_used[match] = True
    print(ans)

if __name__ == '__main__':
    abc091_c()

Submission status: Wrong Answer

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

ans = 0
switch = lambda X:(X[1],X[0])
for b in Blue:
    C = [switch(r) for r in Red if r < b] #候補
    if len(C) == 0:
        continue
    ans += 1
    C.sort(reverse=True)
    Red.remove(switch(C[0]))
print(ans)

Submission status: Wrong Answer

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

ans = 0
for b in Blue:
    C = [r for r in Red if r < b] #候補
    if len(C) == 0:
        continue
    ans += 1
    pair = (0,-1)
    for c in C:
        if c[1] > pair[1]:
            pair = c
    Red.remove(pair)
print(ans)

Submission status: Wrong Answer

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

ans = 0
while len(Red) != 0:
    r = Red.pop(0)
    while len(Blue) != 0:
        b = Blue.pop(0)
        Rem = []
        if r < b:
            ans += 1
            for rem in reversed(Rem):
                Blue.insert(0,rem)
            break
        else:
            Rem.append(b)      
print(ans)

Submission status: Wrong Answer

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

ans = 0
while len(Blue) != 0:
    r = Red.pop(0)
    while len(Blue) != 0:
        b = Blue.pop(0)
        if r < b:
            ans += 1
            break
print(ans)

Submission status: Wrong Answer

Solution code:

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

for i in range(n):
    '''
    kagi_r = [min(red[i][0], red[i][1]), max(red[i][0], red[i][1])]
    kagi_b = [min(blue[i][0], blue[i][1]), max(blue[i][0], blue[i][1])]
    red[i] = red[i] + kagi_r
    blue[i] = blue[i] + kagi_b
    '''
red.sort(key=lambda x: (x[0], x[1]), reverse=True)
blue.sort(key=lambda x: (x[0], x[1]))
flg_r = [0]*n
cnt = 0

for i in range(n):
    for j in range(n):
        if flg_r[j]:
            continue
        if red[j][0] < blue[i][0] and red[j][1] < blue[i][1]:
            flg_r[j] = 1
            cnt += 1
            break

print(cnt)

Submission status: Wrong Answer

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

for i in range(n):
    kagi_r = [min(red[i][0], red[i][1]), max(red[i][0], red[i][1])]
    kagi_b = [min(blue[i][0], blue[i][1]), max(blue[i][0], blue[i][1])]
    red[i] = red[i] + kagi_r
    blue[i] = blue[i] + kagi_b
red.sort(key=lambda x: (x[2], x[3]))
blue.sort(key=lambda x: (x[2], x[3]))
flg_b = [0]*n
cnt = 0

for i in range(n):
    for j in range(n):
        if flg_b[j]:
            continue
        if red[i][0] < blue[j][0] and red[i][1] < blue[j][1]:
            flg_b[j] = 1
            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)]
# y座標で降順ソート
red.sort(reverse=True)
# x座標でソート
blue.sort(key=lambda x: x[1])

# print(red)
# print(blue)

red_list = [0] * N
blue_list = [0] * N


for b in range(N):
    for r in range(N):
        if blue_list[b] == 1 or red_list == 1:
            continue
        if red[r][0] < blue[b][0] and red[r][1] < blue[b][1]:
            # print(b, r)
            blue_list[b] = 1
            red_list[r] = 1
            break

print(sum(blue_list))

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)]
# y座標で降順ソート
red.sort(reverse=True)
# x座標でソート
blue.sort(key=lambda x: x[1])

print(red)
print(blue)

red_list = [0] * N
blue_list = [0] * N


for b in range(N):
    for r in range(N):
        if blue_list[b] == 1 or red_list == 1:
            continue
        if red[r][0] < blue[b][0] and red[r][1] < blue[b][1]:
            print(b, r)
            blue_list[b] = 1
            red_list[r] = 1
            break

print(sum(blue_list))

Submission status: Wrong Answer

Solution code:
n=int(input())
R=sorted([list(map(int,input().split())) for i in range(n)], key=lambda R: -R[1])
B=sorted([list(map(int,input().split())) for i in range(n)])
print(R)
print(B)
ans=0
for c,d in B:
  for a,b in R:
    if a<c and b<d:
      R.remove([a,b]);ans+=1
      break
print(ans)

Submission status: Wrong Answer

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

for g in range(n):
    cd.append(tuple(map(int,input().split())))

ab.sort(key=lambda x: x[1], reverse = True)
cd.sort()
used = [False]*n

ans = 0
for i in range(n):
    for g in range(n):
        if ab[i] < cd[g] and not used[g]:
            used[g] = True
            ans += 1
            break
print(ans)

Submission status: Wrong Answer

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

for g in range(n):
    cd.append(tuple(map(int,input().split())))

ab.sort(key=lambda x: x[1])
cd.sort()
used = [False]*n

ans = 0
for i in range(n):
    for g in range(n):
        if ab[i] < cd[g] and not used[g]:
            used[g] = True
            ans += 1
            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)]

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

for x,y in B:
    if x>R[0][0] and y>R[0][1]:
        ans += 1
        R.pop(0)
print(ans)

Submission status: Wrong Answer

Solution code:
#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
import heapq
#from fractions  import gcd
#input=sys.stdin.readline
import bisect
n=int(input())
ab=[list(map(int,input().split())) for _ in range(n)]
cd=[list(map(int,input().split())) for _ in range(n)]
res=[[] for _ in range(n)]
ans=0
cnt=set()
for i in range(n):
    a,b=ab[i]
    for j in range(n):
        c,d=cd[j]
        if a<c and b<d:
            e=(d-b)+(c-a)
            res[i].append([e,j])
    res[i].sort()
res=sorted(res,key=lambda x:len(x) )
for i in range(n):
    l=len(res[i])
    for k in range(l):
        e,j=res[i][k]
        if j not in cnt:
            cnt.add(j)
            ans+=1
            break
print(ans)

Submission status: Wrong Answer

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

B = []
for i in range(N):
    B.append(tuple(map(int, input().split())))
B.sort(key=lambda x: (x[0], -x[1]))

count = i = 0

for a in A:
    while 1:
        if N == i:
            print(count)
            exit()
        elif B[i] <= a:
            i += 1
        else:
            i += 1
            break
    count += 1
print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = []
for i in range(N):
    A.append(tuple(map(int, input().split())))
A.sort(key=lambda x: (x[0], x[1]))

B = []
for i in range(N):
    B.append(tuple(map(int, input().split())))
B.sort(key=lambda x: (x[0], x[1]))

count = i = 0

for a in A:
    while 1:
        if N == i:
            print(count)
            exit()
        elif B[i] <= a:
            i += 1
        else:
            i += 1
            break
    count += 1
print(count)

Submission status: Wrong Answer

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

B = []
for i in range(N):
    B.append(tuple(map(int, input().split())))
B.sort()

count = i = 0

for a in A:
    while 1:
        if N == i:
            print(count)
            exit()
        if B[i] <= a:
            i += 1
        else:
            i += 1
            break
    count += 1
print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = []
for i in range(N):
    A.append(tuple(map(int, input().split())))
A.sort(key=lambda x: (x[0], x[1]))

B = []
for i in range(N):
    B.append(tuple(map(int, input().split())))
B.sort(key=lambda x: (x[0], x[1]))

count = i = 0

for a in A:
    while 1:
        if len(B) == i:
            print(count)
            exit()
        if B[i][0] <= a[0] or B[i][1] <= a[1]:
            i += 1
        else:
            i += 1
            break
    count += 1
print(count)

Submission status: Wrong Answer

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

B = []
for i in range(N):
    B.append(tuple(map(int, input().split())))
B.sort()

count = i = 0

for a in A:
    while 1:
        if len(B) == i:
            print(count)
            exit()
        if B[i] <= a:
            i += 1
        else:
            i += 1
            break
    count += 1
print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
Red  = [[int(T) for T in input().split()] for TN in range(0,N)]
Blue = [[int(T) for T in input().split()] for TN in range(0,N)]
Count = 0
for TB in range(0,N):
    MIN = 500
    MINInd = -1
    for TR in range(0,len(Red)):
        if Blue[TB][0]>Red[TR][0] and Blue[TB][1]>Red[TR][1]:
            Dist = (Blue[TB][0]-Red[TR][0])+(Blue[TB][1]>Red[TR][1])
            if MIN>Dist:
                MIN = Dist
                MINInd = TR
    if MINInd!=-1:
        del Red[MINInd]
        Count += 1
print(Count)

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):
  a,b=map(int,input().split())
  blue.append([a,b])
maxdore=[]
for i in range(n):
  counter=0
  for j in range(n):
    if blue[j][0]-red[i][0]>0 and blue[j][1]-red[i][1]:
      counter+=1
  maxdore.append(counter)
print(max(maxdore))

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    red = []
    red_used = [[False for _ in range(2 * n)] for _ in range(2 * n)]
    for _ in range(n):
        rp = list(map(int, input().split()))
        red.append(rp)
        red_used[rp[0]][rp[1]] = True
    ans = 0
    red.sort(key=lambda x: x[0])
    blue = [list(map(int, input().split())) for _ in range(n)]
    blue.sort(key=lambda x: x[0])
    for bp in blue:
        now_x = -1
        now_y = -1
        min_diff = float("inf")
        for i in range(n):
            now = 0
            for j in range(2):
                now += bp[j] - red[i][j] if bp[j] - red[i][j] >= 0 else 10 ** 9
            if 0 < now < min_diff and red_used[red[i][0]][red[i][1]] and all(red[i][j] < bp[j] for j in range(2)):
                now_x, now_y = red[i]
                min_diff = now
        if now_x != -1 and now_y != -1:
            red_used[now_x][now_y] = False
            ans += 1
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    red = []
    red_used = [[False for _ in range(2 * n)] for _ in range(2 * n)]
    for _ in range(n):
        rp = list(map(int, input().split()))
        red.append(rp)
        red_used[rp[0]][rp[1]] = True
    ans = 0
    for _ in range(n):
        bp = list(map(int, input().split()))
        now_x = -1
        now_y = -1
        min_diff = float("inf")
        for i in range(n):
            now = 0
            for j in range(2):
                now += bp[j] - red[i][j] if bp[j] - red[i][j] >= 0 else 10 ** 9
            if 0 < now < min_diff and red_used[red[i][0]][red[i][1]] and all(red[i][j] < bp[j] for j in range(2)):
                now_x, now_y = red[i]
                min_diff = now
        if now_x != -1 and now_y != -1:
            red_used[now_x][now_y] = False
            ans += 1
    print(ans)


if __name__ == '__main__':
    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):
  a,b=map(int,input().split())
  blue.append([a,b])
maxdore=[]
for i in range(n):
  counter=0
  for j in range(n):
    if blue[j][0]-red[i][0]>0 and blue[j][1]-red[i][0]:
      counter+=1
  maxdore.append(counter)
print(max(maxdore))

Submission status: Wrong Answer

Solution code:
import networkx as nx

n = int(input())
graph = nx.Graph()
AB = [list(map(int, input().split())) for _ in range(n)]
CD = [list(map(int, input().split())) for _ in range(n)]
AB.sort()
CD.sort()
start = 10 ** 4
goal = 10 ** 4 + 1
for i in range(n):
    a, b = AB[i]
    graph.add_edge(start, i, weight=0, capacity=1)
    for j in range(n):
        c, d = CD[j]
        graph.add_edge(200 + j, goal, weight=0, capacity=1)
        if c > a and d > b:
            graph.add_edge(i, 200 + j, weight=0, capacity=1)

ans = nx.maximum_flow(graph, start, goal, capacity="capacity")
print(ans[0])

Submission status: Wrong Answer

Solution code:
N=int(input())
red=list()
blue=list()
for i in range(N):
  a,b=map(int,input().split())
  red.append([a,b])
for i in range(N):
  a,b=map(int,input().split())
  blue.append([a,b])
red=sorted(red,reverse=True)
blue=sorted(blue,reverse=True)
ans=0
blue2=[i for i in blue]
for i in range(N):
  a=red[i][0]
  b=red[i][1]
  #red[i]とペアになる最小の奴
  s=[x for x in blue2 if x[0]>=a and x[1]>=b]
  if len(s)!=0:
    blue2.remove(s[0])
    ans+=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)]

res = 0
for rx, ry in red:
    dist = float('inf')
    for bx, by in blue:
        if bx > rx and by - ry and (bx - rx) + (by - ry) < dist:
            dist = (bx - rx) + (by - ry)
            mx, my = bx, by
    
    if dist != float('inf'):
        res += 1
        blue.remove([mx, my])

print(res)

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[1], x[0]))
cd.sort(key=lambda x: (x[0], x[1]))
s = [0] * n
print(ab)
print(cd)

for i in range(n):
    for j in range(n):
        if s[j] == 0 and ab[j][0] < cd[i][0] and ab[j][1] < cd[i][1]:
            s[j] = 1
            break
print(sum(s))