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:
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()

#####Shorten#####
def DD(arg): return defaultdict(arg)


#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####MakePrimes######
def make_primes(N):
  max = int(math.sqrt(N))
  seachList = [i for i in range(2,N+1)]
  primeNum = []
  while seachList[0] <= max:
    primeNum.append(seachList[0])
    tmp = seachList[0]
    seachList = [i for i in seachList if i % tmp != 0]
  primeNum.extend(seachList)
  return primeNum

#####GCD#####
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############
N = I()
R = ILL(N)
B = ILL(N)

graphR = [[] for _ in range(N)]
graphB = [[] 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]:
      graphR[i].append(j)
      graphB[j].append(i)

ans1 =  set()
for i in range(N):
  for j in graphR[i]:
    ans1.add(j)
ans2 =  set()
for i in range(N):
  for j in graphB[i]:
    ans2.add(j)
print(min(len(ans1),len(ans2)))

Submission status: Wrong Answer

Solution code:
N = int(input())
xs = []
ys = []

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

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

used = []
ret = 0
for (a, b) in xs:
    l = []
    for (c, d) in ys:
        if a < c and b < d:
            l.append((c, d))

    aa = None
    for (c, d) in l:
        if used.count((c, d)) == 1:
            continue
        if aa is None:
            aa = (c, d)
        elif aa[1] < d:
            aa = (c, d)

    if aa is not None:
        used.append((c, d))
        ret += 1

print(ret)

Submission status: Wrong Answer

Solution code:
N = int(input())
xs = []
ys = []

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

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

s1 = set()
s2 = set()

for (a, b) in xs:
    for (c, y) in ys:
        if a < c and b < y:
            s1.add((a, b))
            s2.add((c, d))

print(min(len(s1), len(s2)))

Submission status: Wrong Answer

Solution code:
N = int(input())
xs = []
ys = []

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

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

s = set()

for (a, b) in xs:
    for (c, y) in ys:
        if a < c and b < y:
            s.add((c, y))

print(len(s))

Submission status: Wrong Answer

Solution code:
n = int(input())

red = []
blue = []

for i in range(n):
    array = list(map(int, input().split()))
    red.append(array)

for i in range(n):
    array = list(map(int, input().split()))
    blue.append(array)

red.sort(key=lambda x:x[1], reverse=True)
blue.sort(key=lambda x:x[0])

# print(red)
# print(blue)

pairs = [[] for _ in range(n)]

cnt = 0
for i, j in blue:
    for x, y in red:
        if i > x and j > y:
            pairs[cnt].append([x, y])
    cnt += 1

pairs.sort(key=lambda x:len(x))
# print(pairs)

for i in range(n):
    if len(pairs[i]) > 1:
        t = pairs[i].pop(0)
        pairs[i].clear()
        pairs[i].append(t)
        for j in range(i+1, n):
            if t in pairs[j]:
                pairs[j].remove(t)
    elif len(pairs[i]) == 1:
        t = pairs[i][0]
        for j in range(i+1, n):
            if t in pairs[j]:
                pairs[j].remove(t)
    else:
        continue

ans = 0
for i in range(n):
    if len(pairs[i]) >= 1:
        ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

red = []
blue = []

for i in range(n):
    array = list(map(int, input().split()))
    red.append(array)

for i in range(n):
    array = list(map(int, input().split()))
    blue.append(array)

red.sort(key=lambda x:x[1], reverse=True)
blue.sort(key=lambda x:x[0])

print(red)
print(blue)

pairs = [[] for _ in range(n)]

cnt = 0
for i, j in blue:
    for x, y in red:
        if i > x and j > y:
            pairs[cnt].append([x, y])
    cnt += 1

pairs.sort(key=lambda x:len(x))
print(pairs)

for i in range(n):
    if len(pairs[i]) > 1:
        t = pairs[i].pop(0)
        pairs[i].clear()
        pairs[i].append(t)
        for j in range(i+1, n):
            if t in pairs[j]:
                pairs[j].remove(t)
    elif len(pairs[i]) == 1:
        t = pairs[i][0]
        for j in range(i+1, n):
            if t in pairs[j]:
                pairs[j].remove(t)
    else:
        continue

ans = 0
for i in range(n):
    if len(pairs[i]) >= 1:
        ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

red = []
blue = []

for i in range(n):
    array = list(map(int, input().split()))
    red.append(array)

for i in range(n):
    array = list(map(int, input().split()))
    blue.append(array)

red.sort(key=lambda x:x[1], reverse=True)
blue.sort(key=lambda x:x[0])

pairs = [[] for _ in range(n)]

cnt = 0
for i, j in blue:
    for x, y in red:
        if i > x and j > y:
            pairs[cnt].append([x, y])
    cnt += 1

pairs.sort(key=lambda x:len(x))

for i in range(n):
    if len(pairs[i]) > 1:
        pairs[i].sort(key=lambda x:x[1], reverse=True)
        t = pairs[i].pop(0)
        pairs[i].clear()
        pairs[i].append(t)
        for j in range(i+1, n):
            if t in pairs[j]:
                pairs[j].remove(t)
    elif len(pairs[i]) == 1:
        t = pairs[i][0]
        for j in range(i+1, n):
            if t in pairs[j]:
                pairs[j].remove(t)
    else:
        continue

ans = 0
for i in range(n):
    if len(pairs[i]) >= 1:
        ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

red = []
blue = []

for i in range(n):
    array = list(map(int, input().split()))
    red.append(array)

for i in range(n):
    array = list(map(int, input().split()))
    blue.append(array)

red.sort(key=lambda x:x[1], reverse=True)
blue.sort(key=lambda x:x[0])

pairs = [[] for _ in range(n)]

cnt = 0
for i, j in blue:
    for x, y in red:
        if i > x and j > y:
            pairs[cnt].append([x, y])
    cnt += 1

pairs.sort(key=lambda x:len(x))

for i in range(n):
    if len(pairs[i]) > 1:
        t = pairs[i].pop(0)
        pairs[i].clear()
        pairs[i].append(t)
        for j in range(i+1, n):
            if t in pairs[j]:
                pairs[j].remove(t)
    elif len(pairs[i]) == 1:
        t = pairs[i][0]
        for j in range(i+1, n):
            if t in pairs[j]:
                pairs[j].remove(t)
    else:
        continue

ans = 0
for i in range(n):
    if len(pairs[i]) >= 1:
        ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

red = []
blue = []

for i in range(n):
    array = list(map(int, input().split()))
    red.append(array)

for i in range(n):
    array = list(map(int, input().split()))
    blue.append(array)

pairs = [[] for _ in range(n)]

cnt = 0
for i, j in blue:
    for x, y in red:
        if i > x and j > y:
            pairs[cnt].append([x, y])
    cnt += 1

pairs.sort(key=lambda x:len(x))

for i in range(n):
    if len(pairs[i]) > 1:
        t = pairs[i].pop(0)
        pairs[i].clear()
        pairs[i].append(t)
        for j in range(i+1, n):
            if t in pairs[j]:
                pairs[j].remove(t)
    elif len(pairs[i]) == 1:
        t = pairs[i][0]
        for j in range(i+1, n):
            if t in pairs[j]:
                pairs[j].remove(t)
    else:
        continue

ans = 0
for i in range(n):
    if len(pairs[i]) >= 1:
        ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
N = int(sys.stdin.readline().rstrip())

grid_r = [[0] * 2 * N for _ in range(2 * N)]

for _ in range(N):
    a, b = tuple(map(int, sys.stdin.readline().rstrip().split()))
    grid_r[a][b] = 1

b = [tuple(map(int, sys.stdin.readline().rstrip().split())) for _ in range(N)]

ans = 0
for b_x, b_y in b:
    for x in range(b_x + 1)[::-1]:
        for y in range(b_y + 1):
            if grid_r[x][y] and (x != b_x or y != b_y):
                grid_r[x][y] = 0
                ans += 1
                break
        else:
            continue
        break
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
N = int(sys.stdin.readline().rstrip())

grid_r = [[0] * 2 * N for _ in range(2 * N)]

for _ in range(N):
    a, b = tuple(map(int, sys.stdin.readline().rstrip().split()))
    grid_r[a][b] = 1

b = [tuple(map(int, sys.stdin.readline().rstrip().split())) for _ in range(N)]

ans = 0
for b_x, b_y in b:
    for x in range(b_x + 1)[::-1]:
        for y in range(b_y + 1):
            if grid_r[x][y] and x != b_x and y != b_y:
                grid_r[x][y] = 0
                ans += 1
                break
        else:
            continue
        break
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
N = int(sys.stdin.readline().rstrip())

grid_r = [[0] * 2 * N for _ in range(2 * N)]

for _ in range(N):
    a, b = tuple(map(int, sys.stdin.readline().rstrip().split()))
    grid_r[a][b] = 1

b = [tuple(map(int, sys.stdin.readline().rstrip().split())) for _ in range(N)]

ans = 0
for b_x, b_y in b:
    for x in range(b_x)[::-1]:
        for y in range(b_y):
            if grid_r[x][y]:
                grid_r[x][y] = 0
                ans += 1
                break
        else:
            continue
        break
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
from heapq import heappop,heappush

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([c,d])

    ans = 0
    for i in range(N):
        pairs = []
        for j in range(len(red)):
            x = blue[i][0] - red[j][0]
            y = blue[i][1] - red[j][1]
            if x > 0 and y > 0:
                heappush(pairs, (min(x,y),j))
        if len(pairs) > 0:
            ans += 1
            _, index = heappop(pairs)
            del red[index]
    
    print(ans)


    

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    r = [list(map(int, input().split())) for _ in range(n)]
    b = [list(map(int, input().split())) for _ in range(n)]

    r = [[i[0], i[1], i[0]+i[1]] for i in r]
    b = [[i[0], i[1], i[0]+i[1]] for i in b]
    #右上から考える
    b.sort(key=lambda x: x[2])
    ans = 0

    for nb in b:
        #残っている青玉の一番右上のものと条件を満たすものをサーチする
        r_sorted = [i for i in r if i[0] < nb[0] and i[1] < nb[1]]
        #もし条件を満たすものがるなら
        if r_sorted:
            #その中で一番右上のものを取り除く
            r_sorted.sort(key=lambda x: nb[0]+nb[1]-nb[0]-nb[1], reverse=True)
            r.remove(r_sorted[0])
            ans += 1

    print(ans)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    r = [list(map(int, input().split())) for _ in range(n)]
    b = [list(map(int, input().split())) for _ in range(n)]

    r = [[i[0], i[1], i[0]+i[1]] for i in r]
    b = [[i[0], i[1], i[0]+i[1]] for i in b]
    #右上から考える
    b.sort(key=lambda x: x[2])
    ans = 0

    for nb in b:
        #残っている青玉の一番右上のものと条件を満たすものをサーチする
        r_sorted = [i for i in r if i[0] < nb[0] and i[1] < nb[1]]
        #もし条件を満たすものがるなら
        if r_sorted:
            #その中で一番右上のものを取り除く
            r_sorted.sort(key=lambda x: x[2], reverse=True)
            r.remove(r_sorted[0])
            ans += 1

    print(ans)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import copy
n = int(input())
red_list = []
blue_list = []
for i in range(n):
  a_b = list(map(int,input().split()))
  red_list.append(a_b)
  
for i in range(n):
  c_d = list(map(int,input().split()))
  blue_list.append(c_d)
red_list_2 = copy.copy(red_list)
blue_list_2 = copy.copy(blue_list)
red_list.sort(key=lambda x: x[0])
blue_list.sort(key=lambda x: x[0])
red_list_2.sort(key=lambda x: x[1])
blue_list_2.sort(key=lambda x: x[1])
count_1 = 0
for blue in blue_list:
  for i in range(len(red_list)):
    if blue[0] > red_list[i][0] and blue[1] > red_list[i][1]:
      count_1 += 1
      red_list.pop(i)
      break
count_2 = 0
for blue in blue_list_2:
  for i in range(len(red_list_2)):
    if blue[0] > red_list_2[i][0] and blue[1] > red_list_2[i][1]:
      count_2 += 1
      red_list_2.pop(i)
      break
      
print(max(count_1,count_2))

Submission status: Wrong Answer

Solution code:
#!/usr/bin python3
# -*- coding: utf-8 -*-

def main():
    N = int(input())
    R = [list(map(int,input().split())) for i in range(N)]
    B = [list(map(int,input().split())) for i in range(N)]
    R.sort(key=lambda x:x[1])
    R.sort()
    B.sort(key=lambda x:x[1])
    B.sort()
    ret = 0
    for b in B:
        pairfg = False
        pair = [1000, -1000]
        for r in R:
            if r[0] < b[0] and r[1] < b[1]:
                if r[1]>pair[1]:
                    pairfg = True
                    pair = r
        if pairfg:
            ret += 1
            print(pair,b)
            R.remove(pair)
    print(ret)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin python3
# -*- coding: utf-8 -*-

def main():
    N = int(input())
    R = [list(map(int,input().split())) for i in range(N)]
    B = [list(map(int,input().split())) for i in range(N)]
    R.sort(key=lambda x:x[1])
    R.sort()
    B.sort(key=lambda x:x[1])
    B.sort()
    ret = 0
    for b in B:
        pairfg = False
        pair = None
        for r in R:
            if r[0] < b[0] and r[1] < b[1]:
                pairfg = True
                pair = r
            if r[0] > b[0]:
                break
        if pairfg:
            ret += 1
#            print(pair,b)
            R.remove(pair)
    print(ret)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

RED = sorted(RED, key=lambda x: min(x[0], x[1]))

count = 0
for r in RED:
    if r[0] > r[1]:
        for b in sorted(BLUE, key=lambda x: x[0]):
            if r[0] <= b[0] and r[1] <= b[1]:
                BLUE.remove(b)
                count += 1
                break
    else:
        for b in sorted(BLUE, key=lambda x: x[1]):
            if r[0] <= b[0] and r[1] <= b[1]:
                BLUE.remove(b)
                count += 1
                break
print(count)

Submission status: Wrong Answer

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

RED = sorted(RED, key=lambda x: max(x[0], x[1]))

count = 0
for r in RED:
    if r[0] > r[1]:
        for b in sorted(BLUE, key=lambda x: x[0]):
            if r[0] <= b[0] and r[1] <= b[1]:
                BLUE.remove(b)
                count += 1
                break
    else:
        for b in sorted(BLUE, key=lambda x: x[1]):
            if r[0] <= b[0] and r[1] <= b[1]:
                BLUE.remove(b)
                count += 1
                break
print(count)

Submission status: Wrong Answer

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

RED = sorted(RED, key=lambda x: max(x[0], x[1]))

count = 0
for r in RED:
    if r[0] > r[1]:
        for b in sorted(BLUE, key=lambda x: x[0]):
            if r[0] < b[0] and r[1] < b[1]:
                BLUE.remove(b)
                count += 1
                break
    else:
        for b in sorted(BLUE, key=lambda x: x[1]):
            if r[0] < b[0] and r[1] < b[1]:
                BLUE.remove(b)
                count += 1
                break
print(count)

Submission status: Wrong Answer

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

BLUE = sorted(BLUE, key=lambda x: max(x[0], x[1]), reverse=True)

count = 0
for b in BLUE:
    if b[0] > b[1]:
        for r in sorted(RED, key=lambda x: x[0], reverse=True):
            if r[0] < b[0] and r[1] < b[1]:
                RED.remove(r)
                count += 1
                break
    else:
        for r in sorted(RED, key=lambda x: x[1], reverse=True):
            if r[0] < b[0] and r[1] < b[1]:
                RED.remove(r)
                count += 1
                break
print(count)

Submission status: Wrong Answer

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

BLUE = sorted(BLUE, key=lambda x: max(x[0], x[1]), reverse=True)

count = 0
for b in BLUE:
    if b[0] > b[1]:
        for r in sorted(RED, key=lambda x: x[0], reverse=True):
            if r[0] < b[0] and r[1] < b[1]:
                RED.remove(r)
                count += 1
    else:
        for r in sorted(RED, key=lambda x: x[1], reverse=True):
            if r[0] < b[0] and r[1] < b[1]:
                RED.remove(r)
                count += 1
print(count)

Submission status: Wrong Answer

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

BLUE = sorted(BLUE, key=lambda x: max(x[0], x[1]))
RED = sorted(RED, key=lambda x: max(x[0], x[1]))

count = 0
for b in BLUE:
    candidate = None
    candidate_distance = float('inf')
    for r in RED:
        if r[0] < b[0] and r[1] < b[1]:
            dist = min(b[0] - r[0], b[1] - r[1])
            if candidate_distance > dist:
                candidate = r
                candidate_distance = dist
    if candidate is not None:
        RED.remove(candidate)
        count += 1
print(count)

Submission status: Wrong Answer

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

BLUE = sorted(BLUE, key=lambda x: max(x[0], x[1]), reverse=True)
RED = sorted(RED, key=lambda x: max(x[0], x[1]), reverse=True)

count = 0
for b in BLUE:
    candidate = None
    candidate_distance = float('inf')
    for r in RED:
        if r[0] < b[0] and r[1] < b[1]:
            dist = min(b[0] - r[0], b[1] - r[1])
            if candidate_distance > dist:
                candidate = r
                candidate_distance = dist
    if candidate is not None:
        RED.remove(candidate)
        count += 1
print(count)

Submission status: Wrong Answer

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

BLUE = sorted(BLUE, key=lambda x: x[0] ** 2 + x[1] ** 2, reverse=True)

count = 0
for b in BLUE:
    candidate = None
    candidate_distance = float('inf')
    for r in RED:
        if r[0] < b[0] and r[1] < b[1]:
            dist = min(b[0] - r[0], b[1] - r[1])
            if candidate_distance > dist:
                candidate = r
                candidate_distance = dist
    if candidate is not None:
        RED.remove(candidate)
        count += 1
print(count)

Submission status: Wrong Answer

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

BLUE = sorted(BLUE, key=lambda x: x[0] ** 2 + x[1] ** 2, reverse=True)

count = 0
for b in BLUE:
    candidate = None
    candidate_distance = float('inf')
    for r in RED:
        if r[0] < b[0] and r[1] < b[1]:
            dist = max(b[0] - r[0], b[1] - r[1])
            if candidate_distance > dist:
                candidate = r
                candidate_distance = dist
    if candidate is not None:
        RED.remove(candidate)
        count += 1
print(count)

Submission status: Wrong Answer

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

BLUE = sorted(BLUE, key=lambda x: x[0] ** 2 + x[1] ** 2, reverse=True)

count = 0
for b in BLUE:
    candidate = None
    candidate_distance = float('inf')
    for r in RED:
        if r[0] < b[0] and r[1] < b[1]:
            dist = (r[0] - b[0]) ** 2 + (r[1] - b[1]) ** 2
            if candidate_distance > dist:
                candidate = r
                candidate_distance = dist
    if candidate is not None:
        RED.remove(candidate)
        count += 1
print(count)

Submission status: Wrong Answer

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

count = 0
for b in BLUE:
    candidate = None
    candidate_distance = float('inf')
    for r in RED:
        if r[0] < b[0] and r[1] < b[1]:
            dist = (r[0] - b[0]) ** 2 + (r[1] - b[1]) ** 2
            if candidate_distance > dist:
                candidate = r
                candidate_distance = dist
    if candidate is not None:
        RED.remove(candidate)
        count += 1
print(count)

Submission status: Wrong Answer

Solution code:
n=int(input())
aka=sorted([list(map(int,input().split())) for i in range(n)],key=lambda x:(min(x),max(x)))
ao=sorted([list(map(int,input().split())) for i in range(n)],key=lambda x:(min(x),max(x)))
ans=0
now=0
def enough(a,b):
    return a[0]<b[0]and a[1]<b[1]
ans=0
for a in aka:
    j=(float("INF"),float("INF"))
    ind=-1
    for i in range(len(ao)):
        b=ao[i]
        if enough(a,b) and b[0]<=j[0] and b[1]<=j[1]:
            j=b
            ind=i
    if ind!=-1:
        ans+=1
        del ao[ind]   
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
red = [list(map(int, input().split())) for _ in range(N)]
red.sort()
blue = [list(map(int, input().split())) for _ in range(N)]
flg = [0]*N
for i in range(N):
    tmp_y = -1
    tmp_index = -1
    for k in range(N):
        if blue[i][0] > red[k][0] and flg[k] == 0:
            if tmp_y < red[k][1] and blue[i][1] > red[k][1]:
                tmp_y = red[k][1]
                tmp_index = k
    if tmp_index != -1:
        flg[tmp_index] = 1
print(flg.count(1))

Submission status: Wrong Answer

Solution code:
N = int(input())
red = [list(map(int, input().split())) for _ in range(N)]
red.sort()
print(red)
blue = [list(map(int, input().split())) for _ in range(N)]
flg = [0]*N
for i in range(N):
    tmp_y = -1
    tmp_index = -1
    for k in range(N):
        if blue[i][0] > red[k][0] and flg[k] == 0:
            if tmp_y < red[k][1] and blue[i][1] > red[k][1]:
                tmp_y = red[k][1]
                tmp_index = k
    if tmp_index != -1:
        flg[tmp_index] = 1
print(flg.count(1))

Submission status: Wrong Answer

Solution code:
N = int(input())
red = [list(map(int, input().split())) for _ in range(N)]
red.sort()
blue = [list(map(int, input().split())) for _ in range(N)]
flg = [0]*N
for i in range(N):
    tmp_y = -1
    tmp_index = -1
    for k in range(N):
        if blue[i][0] > red[k][0] and flg[k] == 0:
            if tmp_y < red[k][1]:
                tmp_y = red[k][1]
                tmp_index = k
    if tmp_index != -1:
        flg[tmp_index] = 1
print(flg.count(1))

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)]
nakayoshi = [[] for _ in range(N)]
check = [[] for _ in range(N)]
flg = [0]*N
for i in range(N):
    for k in range(N):
        if red[i][0] < blue[k][0] and red[i][1] < blue[k][1]:
            nakayoshi[k].append(i)
for i in range(N):
    check[i].append(len(nakayoshi[i]))
    check[i].append(nakayoshi[i])
check.sort()
for i in range(N):
    for k in check[i][1]:
        if flg[k] == 0:
            flg[k] = 1
            break
print(flg.count(1))

Submission status: Wrong Answer

Solution code:
from math import factorial

def combinations_count(n, r):
    return factorial(n) // (factorial(n - r) * factorial(r))#組み合わせ

n = int(input())
ab = []                                                                                   
ans = 0
se = set()

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

for _ in range(n):                                                                                                               
    point = 0
    c,d = map(int,input().split())
    for i in ab:
        a,b = i
        if a < c and b < d:
            if (a,b) in se:
                continue
            point += 1
            se.add((a,b))
            break
    ans += point

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
rlst = []
blst = []

for _ in range(n):
    w, h = map(int, input().split())
    rlst.append([w, h])
for _ in range(n):
    w, h = map(int, input().split())
    blst.append([w, h])
    
rlstw = sorted(rlst, key=lambda x:(x[0],x[1]))
rlsth = sorted(rlst, key=lambda x:(x[1],x[0]))

blstw = sorted(blst, key=lambda x:(x[0],x[1]))
blsth = sorted(blst, key=lambda x:(x[1],x[0]))

answ = 0
for r, b in zip(rlstw, blstw):
    if r[0] < b[0] and r[1] < b[1]:    
        answ += 1

ansh = 0
for r, b in zip(rlsth, blsth):
    if r[0] < b[0] and r[1] < b[1]:    
        ansh += 1
                
print(max(answ,ansh))

Submission status: Wrong Answer

Solution code:
n = int(input())
lst = []
for _ in range(n):
    w, h = map(int, input().split())
    lst.append([w, h])

lstw = sorted(lst, key=lambda x:(x[0],x[1]))
lsth = sorted(lst, key=lambda x:(x[1],x[0]))

answ = 0
noww = 0
nowh  = 0
for _ in lstw:
    if noww < _[0] and nowh < _[1]:
        print("FIT",_[0], _[1],'/',noww, nowh)      
        noww = _[0]
        nowh = _[1]
        answ += 1
    else:
        print("UNFIT",_[0], _[1],'/',noww, nowh)     
print(answ)

ansh = 0
noww = 0
nowh  = 0
for _ in lsth:
    if noww < _[0] and nowh < _[1]:
        print("FIT",_[0], _[1],'/',noww, nowh)      
        noww = _[0]
        nowh = _[1]
        ansh += 1
    else:
        print("UNFIT",_[0], _[1],'/',noww, nowh)     
print(max(answ,ansh))

Submission status: Wrong Answer

Solution code:
n=int(input())

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

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

ab.sort()
cd.sort()
cnt=0
for item1 in cd:
  x,y=item1[0],item1[1]
  result=[]
  for item2 in ab:
    xx,yy=item2[0],item2[1]
    if x>xx and y>yy:
      if result==[]:
        result=[xx,yy]
      else:
        if yy<result[1]:
          result=[xx,yy]
  if result!=[]:
    #print(x,y,result)
    ab.remove((result[0],result[1]))
    cnt+=1
print(cnt)