Problem:


Score : 400 points

Problem Statement

On a two-dimensional plane, there are N red points and N blue points.
The coordinates of the i-th red point are (a_i, b_i), and the coordinates of the i-th blue point are (c_i, d_i).

A red point and a blue point can form a friendly pair when, the x-coordinate of the red point is smaller than that of the blue point, and the y-coordinate of the red point is also smaller than that of the blue point.

At most how many friendly pairs can you form? Note that a point cannot belong to multiple pairs.

Constraints

All input values are integers.

1 \leq N \leq 100

0 \leq a_i, b_i, c_i, d_i < 2N

a_1, a_2, ..., a_N, c_1, c_2, ..., c_N are all different.

b_1, b_2, ..., b_N, d_1, d_2, ..., d_N are all different.

Input

Input is given from Standard Input in the following format:

N
a_1 b_1
a_2 b_2
:
a_N b_N
c_1 d_1
c_2 d_2
:
c_N d_N

Output

Print the maximum number of friendly pairs.

Sample Input 1

3
2 0
3 1
1 3
4 2
0 4
5 5

Sample Output 1

2

For example, you can pair (2, 0) and (4, 2), then (3, 1) and (5, 5).

Sample Input 2

3
0 0
1 1
5 2
2 3
3 4
4 5

Sample Output 2

2

For example, you can pair (0, 0) and (2, 3), then (1, 1) and (3, 4).

Sample Input 3

2
2 2
3 3
0 0
1 1

Sample Output 3

0

It is possible that no pair can be formed.

Sample Input 4

5
0 0
7 3
2 2
4 8
1 6
8 5
6 9
5 4
9 1
3 7

Sample Output 4

5

Sample Input 5

5
0 0
1 1
5 5
6 6
7 7
2 2
3 3
4 4
8 8
9 9

Sample Output 5

4



Sample input:
3
2 0
3 1
1 3
4 2
0 4
5 5


Sample output:
2

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[]
b=[]
for i in range(n):
  k=list(map(int,input().split()))
  a.append(k)
a.sort()
a.reverse()
for i in range(n):
  k=list(map(int,input().split()))
  b.append(k)
b.sort()
ans=0
for i in range(n):
  for j in range(1,len(b)+1):
    if a[i][0]<b[-j][0] and a[i][1]<b[-j][1]:
      ans+=1
      b.pop(-j)
      break
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[]
b=[]
for i in range(n):
  k=list(map(int,input().split()))
  a.append(k)
a.sort()
a.reverse()
for i in range(n):
  k=list(map(int,input().split()))
  b.append(k)
b.sort()
ans=0
for i in range(n):
  for j in range(1,len(b)+1):
    if a[i][0]<b[-j][0] and a[i][1]<b[-j][0]:
      ans+=1
      b.pop(-j)
      break
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[]
b=[]
for i in range(n):
  k=list(map(int,input().split()))
  a.append(k)
a.sort()
for i in range(n):
  k=list(map(int,input().split()))
  b.append(k)
b.sort()
b.reverse()
ans=0
for i in range(n):
  if b[i][0]<a[-1][0] and b[i][1]<a[-1][0]:
    ans+=1
    a.pop()
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 j in range(N)]
Bb = list(B)
#print(Bb)
R.sort(reverse=True)
B.sort()
c = 0
for i in range(N):
    for j in range(N-c):
        if R[i][0] < B[j][0] and R[i][1] < B[j][1]:
            c += 1
            #print(R[i][0] , B[j][0] , R[i][1] , B[j][1])
            del B[j]
            break
#print(c)
R.sort(key=lambda x:(x[1],x[0]),reverse=True)
Bb.sort(key=lambda x:(x[1],x[0]))
#print(R,Bb)
d = 0
for i in range(N):
    for j in range(N-d):
        if R[i][0] < Bb[j][0] and R[i][1] < Bb[j][1]:
            d += 1
            #print(R[i][0] , Bb[j][0] , R[i][1] , Bb[j][1])
            del Bb[j]
            break
#print(d)
print(max(c,d))

Submission status: Wrong Answer

Solution code:
N = int(input())
ta = 0
tb = 0
tc = 0
td = 0
a = 0
A = [list(map(int,input().split())) for i in range(N)]
B = [list(map(int,input().split())) for i in range(N)]
A.sort(key = lambda A:A[0])
B.sort(key = lambda B:B[0])
#print(A,B)
for i in range(N):
   # print(B[-1-i])
    for j in range(N):
        #print(i,j,a)
        if a + j >= N:
                #print(A)
            break
        if B[-1-i][0] > A[-1-j][0] and B[-1-i][1] > A[-1-j][1]:
            #print(A[-1-j])
            a += 1
            del A[-1-j]
            break
            #A.remove(A[-1-j])
        # if a + j >= N:
        #         #print(A)
        #     break
print(a)

Submission status: Wrong Answer

Solution code:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def pf(s): return print(s, flush=True)

N = I()
A,B = [], []
for n in range(N):
    A.append(LI())
for n in range(N):
    B.append(LI())

"""
一旦赤い点がどの青い点を持てるのかを洗い出す
lenが小さい順に青を消していく。
何個消せるかで勝負
"""

b_a = []
for b in B:
    tmp = []
    for a in A:
        if a[0] < b[0] and a[1] < b[1]:
            # 赤が青より小さいとき
            tmp.append(a)
    if tmp:
        b_a.append(tmp)
#  print(b_a)

result = 0
for i in range(len(b_a)-1, -1, -1):
    b_a = sorted(b_a, reverse=True, key=lambda x: len(x))
    popped = b_a.pop()[0]
    result += 1
    #  print('popped', popped)
    b_a = [[k for k in j if k != popped] for j in b_a]
    b_a = [j for j in b_a if j != []]
    #  print(b_a)
    if not b_a:
        break
    #  b_a = [1:]
    #  b_a[0]
print(result)

Submission status: Wrong Answer

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

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

red_x = sorted(red)
blue_x = sorted(blue)
red_y = sorted(red, key=lambda x: x[1])
blue_y = sorted(blue, key=lambda x: x[1])

def count(rr, bb):
    cnt = 0
    for i in range(N):
        a, b = rr[i]
        k = -1
        for j in range(len(bb)):
            c, d = bb[j]
            if a < c and b < d:
                k = j
                break
        if k != -1:
            bb.pop(k)
            cnt += 1
    return cnt

maxv = 0
maxv = max(maxv, count(red_x, blue_x))
maxv = max(maxv, count(red_x, blue_y))
maxv = max(maxv, count(red_y, blue_x))
maxv = max(maxv, count(red_y, blue_y))
print(maxv)

Submission status: Wrong Answer

Solution code:
import collections
import itertools

def check_points(b, r):
    if b[0] <= r[0]:
        return False
    else:
        if b[1] <= r[1]:
            return False
        else:
            return True

def distance(b, r):
    return abs(b[0]-r[0])**2 + abs(b[1]-r[1])**2

n = int(input())
pr =[]
for i in range(n):
    pr.append(list(map(int, input().split())))

pb = []
for l in range(n):
    pb.append(list(map(int, input().split())))

pbr = []
for b, r in itertools.product(pb, pr):
    pbr.append((b, r, distance(b, r)))
pbr = sorted(pbr, key = lambda x:x[2])

ans = 0
pr_ = []
pb_ = []
for b, r, d in pbr:
    if b in pb_ or r in pr_:
        continue

    if check_points(b, r):
        pr_.append(r)
        pb_.append(b)
        ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
# /usr/bin/python
# -*- coding: utf-8 -*-
#
import sys

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

l = [0] * n # b > a を満たすaの数
for i in range(n):
  for j in range(n):
    if blue[i][0] > red[j][0] and blue[i][1] > red[j][1]:
      l[i] += 1
l = sorted(l)

df = 0
for i in range(n):
  if l[i] > df:
    df += 1
print(df)

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007

#A
def A():
    return

#B
def B():
    return

#C
def C():
    n = II()
    ab = LIR(n)
    cd = LIR(n)
    ab.sort()
    check = [0 for i in range(n)]
    ans = 0
    #print(ab)
    for i, c in enumerate(cd):
        d = c[1]
        c = c[0]
        maxy = -1
        x = -1
        for k, a in enumerate(ab):
            b = a[1]
            a = a[0]
            if maxy < b and c > a and check[k] == 0 and d > b:
                maxy = b
                x = k
                #print(a,b,c,d)
        if x != -1:
            ans += 1
            check[x] += 1
    print(ans)


    return

#D
def D():
    n = II()
    ab = LI()
    cd = LI()
    binab = []
    bincd = []
    warerua = [0 for i in range(28)]
    wareruc = [0 for i in range(28)]
    warenaib = [0 for i in range(28)]
    warenaid = [0 for i in range(28)]
    for i in range(n):
        ab[i] = list(bin(ab[i]))[2:]
        ab[i] = ab[i][::-1]
        cd[i] = list(bin(cd[i]))[2:]
        cd[i] = cd[i][::-1]
    for i in range(n):
        for k in range(len(ab[i])):
            #print(warerua, warenaib, wareruc, warenaid,ab[i][k])
            if ab[i][k] == "1":
                warenaib[k] += 1
            else:
                warerua[k] += 1
        for k in range(len(ab[i]), 28):
            warerua[k] += 1
        for k in range(len(cd[i])):
            if cd[i][k] == "1":
                warenaid[k] += 1
            else:
                wareruc[k] += 1
        for k in range(len(ab[i]), 28):
            wareruc[k] += 1
    ans = 0
    print(warerua, warenaib, wareruc, warenaid)
    for i in range(28):
        kisu = warerua[i] * warenaid[i] + warenaib[i] * wareruc[i]
        gusu = warerua[i] * wareruc[i] + warenaib[i] * warenaid[i]
        if kisu % 2:
            ans += 1 << i
    print(ans)
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    C()

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007

#A
def A():
    return

#B
def B():
    return

#C
def C():
    n = II()
    ab = LIR(n)
    cd = LIR(n)
    ab.sort()
    check = [0 for i in range(n)]
    ans = 0
    #print(ab)
    for i, a in enumerate(ab):
        b = a[1]
        a = a[0]
        miny = b
        x = -1
        for k, c in enumerate(cd):
            d = c[1]
            c = c[0]
            if miny < d and c > a and check[k] == 0:
                miny = d
                x = k
                #print(a,b,c,d)
        if x != -1:
            ans += 1
            check[x] += 1
    print(ans)


    return

#D
def D():
    n = II()
    ab = LI()
    cd = LI()
    binab = []
    bincd = []
    warerua = [0 for i in range(28)]
    wareruc = [0 for i in range(28)]
    warenaib = [0 for i in range(28)]
    warenaid = [0 for i in range(28)]
    for i in range(n):
        ab[i] = list(bin(ab[i]))[2:]
        ab[i] = ab[i][::-1]
        cd[i] = list(bin(cd[i]))[2:]
        cd[i] = cd[i][::-1]
    for i in range(n):
        for k in range(len(ab[i])):
            #print(warerua, warenaib, wareruc, warenaid,ab[i][k])
            if ab[i][k] == "1":
                warenaib[k] += 1
            else:
                warerua[k] += 1
        for k in range(len(ab[i]), 28):
            warerua[k] += 1
        for k in range(len(cd[i])):
            if cd[i][k] == "1":
                warenaid[k] += 1
            else:
                wareruc[k] += 1
        for k in range(len(ab[i]), 28):
            wareruc[k] += 1
    ans = 0
    print(warerua, warenaib, wareruc, warenaid)
    for i in range(28):
        kisu = warerua[i] * warenaid[i] + warenaib[i] * wareruc[i]
        gusu = warerua[i] * wareruc[i] + warenaib[i] * warenaid[i]
        if kisu % 2:
            ans += 1 << i
    print(ans)
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    C()

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A
def A():
    return

#B
def B():
    return

#C
def C():
    n = I()
    r = LIR(n)
    b = LIR(n)
    v = [[[],i,0] for i 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]:
                v[i][0].append(j)
                v[i][2] += 1
    v.sort(key = lambda x:x[2])
    ans = 0
    f = [1 for i in range(n)]
    for vi,i,a in v:
        for j in vi:
            if f[j]:
                ans += 1
                f[j] = 0
                break
    print(ans)
#D
def D():
    n = I()
    a = LI()
    b = LI()
    s = 0
    for i in range(n):
        s ^= b[i]
    ans = 0
    print(s)
    for i in range(n):
        s ^= a[i]
    print(s)

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == "__main__":
    C()

Submission status: Wrong Answer

Solution code:
import math
def p(d): print(d)
def i(): return input()

def LI():  # Line Integer
    # 1行 1つの数字
    return int(input())
def LIS():  # Line IntegerS
    # 1行 mつの数字
    return [int(x) for x in input().split()]
def MLIS(n):  # Multi Line IntegerS
    # n行 mつの数字
    return [[int(x) for x in input().split()] for y in range(n)]
def LC():  # Line Character
    # 1行 1つの文字
    return input()
def LCS(): # Line CharacterS
    # 1行 nつの文字
    return [x for x in input().split()]
def MLCS(n): # Multi Line CharacterS
    # n行 mつの数字
    return [[x for x in input().split()] for y in range(n)]

def alp2int(alphabet):
    # アルファベットの番号を返す
    return ord(alphabet) - ord('a')
def int2alp(num):
    # 番号からアルファベットを返す
    return chr(num + ord('a'))
def cnt2dic(lst, dic={}):
    # 同じものをカウントして辞書型にする
    for x in lst:
        key = str(x)
        if key in dic:
            dic[key] += 1
        else:
            dic[key] = 1
    return dic
def dic2lst(dic, key=lambda x:x[1]):
    # 辞書をタプルの配列にする
    return sorted(list(dic.items()), key=key);

def A():
    a = LC()
    if a[0] == a[2]:
        print('Yes')
    else:
        print('No')

def B():
    a, b, c, d = LIS()
    s = max(a, c)
    e = min(b, d)
    if s < e:
        p(e-s)
    else:
        p(0)

def C():
    N = LI()
    reds = sorted(MLIS(N), key=lambda x:x[0])
    blues = sorted(MLIS(N), key=lambda x:x[0])

    blueF = [False for x in range(N)]

    count = 0

    for i in range(N):
        for j in range(N):
            if blueF[j] == False and reds[i] < blues[j]:
                blueF[j] = True
                count += 1
                break
    print(count)

def D():
    pass

def E():
    pass

def F():
    pass

def G():
    pass

def H():
    pass

C()

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())
red = np.array(sorted(list(map(int, input().split())) for _ in range(n)))
blue = np.array(sorted(list(map(int, input().split())) for _ in range(n)))
used = []
pair = 0

for i in range(n):
    sub = blue - red[i]
    min_0 = 200
    min_1 = 200
    for j in range(n):
        if j not in used and min(sub[j]) > 0 and (sub[j][0] < min_0 or sub[j][1] < min_1):
                min_0 = sub[j][0]
                min_1 = sub[j][1]
                k = j
    if min_0 != 200 or min_1 != 200:
        pair += 1
        used.append(k)

print(pair)

Submission status: Wrong Answer

Solution code:
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**9)

class FordFulkerson:
    def __init__(self,n):
        self.visited=[False]*n
        self.G=[[0]*n for _ in range(n)]
        self.n=n
    def add_edge(self,fr,to,cap):
        self.G[fr][to]=cap
        self.G[to][fr]=cap
    def dfs(self,start,goal,f):
        if start==goal:
            return f
        self.visited[start]=True
        for i in range(self.n):
            if i==start:
                continue
            if (not self.visited[i]) and self.G[start][i]>0:
                d=self.dfs(i,goal,min(f,self.G[start][i]))
                if d>0:
                    self.G[start][i]-=d
                    self.G[i][start]+=d
                    return d
        return 0
    def maxflow(self,a,b):
        flow=0
        while True:
            self.visited=[False]*self.n
            f=self.dfs(a,b,float('inf'))
            if f==0:
                break
            flow+=f
        return flow

def BipartiteMatching(Pairs,a,b):
    solver=FordFulkerson(a+b+2)
    for x,y in Pairs:
        solver.add_edge(x,a+y,1)
    for x in range(a):
        solver.add_edge(0,x+1,1)
    for y in range(b):
        solver.add_edge(a+y+1,a+b+1,1)
    return solver.maxflow(0,a+b+1)

n=int(input())
R=[list(map(int,input().split())) for _ in range(n)]
B=[list(map(int,input().split())) for _ in range(n)]
Pairs=[]
for i in range(n):
    for j in range(n):
        if R[i][0]<B[j][0] and R[i][1]<B[j][1]:
            Pairs.append((i+1,j+1))
print(BipartiteMatching(Pairs,n,n))

Submission status: Wrong Answer

Solution code:
n = int(input())
red, brue = [], []
for _ in range(n):
  x, y = map(int, input().split())
  red.append([x, y])
for _ in range(n):
  x, y = map(int, input().split())
  brue.append([x, y])
red, brue = sorted(red), sorted(brue)
used = [False for _ in range(n)]
ans = 0
for i in range(n):
  x, y = red[i][0], red[i][1]
  for j in range(n):
    if used[j] or x >= brue[j][0] or y >= brue[j][1]:
      continue
    used[j] = True
    ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
red = [list(map(int, input().split())) for i in range (N)]
blue = [list(map(int, input().split())) for i in range (N)]
blue.sort(key=lambda x:x[0])
red.sort(key=lambda x:x[1])
pairs = 0
flag = [True for i in range(N)]
for i in range(N):
    for j in range(N):
        if blue[i][0] > red[j][0] and blue[i][1] > red[j][1] and flag[j]:
            pairs += 1
            flag[j] = False
            break
print(pairs)

Submission status: Wrong Answer

Solution code:

N = int(input())
red_ls = list()
blue_ls = list()
for i in range(N):
    red_ls.append([int(i) for i in input().split()])
for i in range(N):
    blue_ls.append([int(i) for i in input().split()])
red_ls = sorted(red_ls, key=lambda x:(x[0], x[1]), reverse=True)
#red_x, red_y = zip(*red_ls)
blue_ls = sorted(blue_ls, key=lambda x:(x[0], x[1]), reverse=True)

blue_ind = 0
red_ind = 0
cnt = 0
pre_ind = -1
yet_ls = list()
for (blue_x, blue_y) in blue_ls:
    flg = 0
    for ind, (red_x, red_y) in enumerate(red_ls):
        if red_y >= blue_y:
            continue
        if red_x >= blue_x:
            continue
        if ind in yet_ls:
            continue
        cnt += 1
        yet_ls.append(ind)
        break
print(cnt)

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)]
b.sort()
r = sorted(r,key=lambda x:-x[1])
ans = 0
for i,b_ in enumerate(b):
    print(r)
    for j,r_ in enumerate(r):
        if b_[0]>r_[0] and b_[1]>r_[1]:
            ans+=1
            del r[j]
            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)]
b.sort()
r = sorted(r,key=lambda x:-x[1])
ans = 0
for i,b_ in enumerate(b):
    for j,r_ in enumerate(r):
        if b_[0]>r_[0]:
            ans+=1
            del r[j]
            break

print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    red = sorted(
        [list(map(int, input().split())) for _ in range(N)],
        key=lambda x: x[1],
        reverse=True
    )
    blue = [list(map(int, input().split())) for _ in range(N)]
    ans = 0
    for b in blue:
        for i, r in enumerate(red):
            if b[0] > r[0] and b[1] > r[1]:
                ans += 1
                red.pop(i)
                break
    print(ans)


main()

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    red = sorted(
        [list(map(int, input().split())) for _ in range(N)],
        key=lambda x: x[1],
        reverse=True
    )
    blue = [list(map(int, input().split())) for _ in range(N)]
    ans = 0
    for b in blue:
        for i, r in enumerate(red):
            if b[0] >= r[0] and b[1] >= r[1]:
                ans += 1
                red.pop(i)
                break
    print(ans)


main()

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)]
blue.sort()
red.sort()
#greedy
ret = 0
used = set()
for x, y in blue:
    koho = -1
    mostright = -1
    for i in range(len(red)):
        if i not in used:
            if red[i][0] >= x:
                break
            elif red[i][1] > mostright:
                koho = i
                mostright = red[i][1]
    if koho != -1:
        ret += 1
        used.add(koho)
print(ret)

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)]
blue.sort()
red.sort()
#greedy
ret = 0
used = set()
for x, y in blue:
    koho = -1
    mostright = -1
    for i in range(len(red)):
        if i not in used:
            if red[i][0] >= x:
                break
            elif red[i][1] > mostright:
                koho = i
    if koho != -1:
        ret += 1
        used.add(koho)
print(ret)

Submission status: Wrong Answer

Solution code:
#ABC091C
n=int(input())
red=[]
blue=[]
for i in range(n):
    red.append(tuple(map(int,input().split())))
for j in range(n):
    blue.append(tuple(map(int,input().split())))
red.sort(key=lambda x:x[0],reverse=True)
blue.sort(key=lambda y:y[0],reverse=True)
def rb(red,blue,ans):
    check=0
    flag=True
    bef=ans
    while True:
        if check==0:flag=False
        if check>=len(red):
            if flag==False:break
            elif flag==True:
                check=0
                continue
        idx=-1
        for i in range(len(blue)):
            if red[check][0]<blue[i][0] and red[check][1]<blue[i][1]:
                if idx!=-1:
                    idx=-1
                    break
                idx=i
        if idx!=-1:
            red.pop(check)
            blue.pop(idx)
            flag=True
            ans+=1
        elif idx==-1:
            check+=1
    if bef==ans:res=False
    elif bef!=ans:res=True
    return ans,res
def br(red,blue,ans):
    check=1
    flag=True
    bef=ans
    while True:
        if check==1:flag=False
        if check>len(blue):
            if flag==False:break
            elif flag==True:
                check=1
                continue
        idx=-1
        for i in range(len(red)-1,-1,-1):
            if red[i][0]<blue[-1*check][0] and red[i][1]<blue[-1*check][1]:
                if idx!=-1:
                    idx=-1
                    break
                idx=i
        if idx!=-1:
            red.pop(idx)
            blue.pop(-1*check)
            flag=True
            ans+=1
        elif idx==-1:
            check+=1
    if bef==ans:res=False
    elif bef!=ans:res=True
    return ans,res
res=True
ans=0
while res==True:
    ans,resa=rb(red,blue,ans)
    ans,resb=br(red,blue,ans)
    if resa==False and resb==False:res=False
blueused=set()
for i in range(len(red)):
    for j in range(len(blue)):
        if j in blueused:continue
        if red[i][0]<blue[j][0] and red[i][1]<blue[j][1]:
            ans+=1
            blueused|={j,}
            break
print(ans)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter

N = int(input())
ab = [list(map(int, input().split())) for i in range(N)]
cd = [list(map(int, input().split())) for i in range(N)]
ab = sorted(ab, key=itemgetter(0,1), reverse=True)
cd = sorted(cd, key=itemgetter(0,1), reverse=True)
count = 0

for a, b in ab:
    for idx in range(len(cd)):
        c, d = cd[idx]

        if a < c and b < d:
            count += 1
            del cd[idx]
            break
print(count)

Submission status: Wrong Answer

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

C = [[0 for i in range(n+2)] for j in range(n)]

for i in range(n): #各青い点について
    for j in range(n): #各赤い点について
        if A[j][0] < B[i][0] and A[j][1] < B[i][1] :
            C[j][i] = 1
            C[j][n] += 1
#print(C)

ans=0

for i in range(n): #各青い点について
    akamin=-1
    mi=100000
    for j in range(n):

        if C[j][i]==1 and C[j][n+1]==0 :
            if mi>C[j][n] :
                mi=C[j][n]
                akamin=j
                #print("{} {}".format(i,akamin))
    if akamin!=-1 :
        C[akamin][n+1]=1
        ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
ab = [list(map(int,input().split())) for i in range(N)]
cd = [list(map(int,input().split())) for i in range(N)]
ab.sort()
cd.sort(reverse=True)
count=0
for i in range(N):
    cdlen = len(cd)
    j=0
    for j in range(cdlen):
        if ab[i][0]<cd[j][0] and ab[i][1]<cd[j][1]:
            count+=1
            del cd[j]
            break
print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
ab = [list(map(int,input().split())) for i in range(N)]
cd = [list(map(int,input().split())) for i in range(N)]
ab.sort(reverse=True)
cd.sort(reverse=True)
count=0
for i in range(N):
    cdlen = len(cd)
    j=0
    for j in range(cdlen):
        if ab[i][0]<cd[j][0] and ab[i][1]<cd[j][1]:
            count+=1
            del cd[j]
            break
print(count)

Submission status: Wrong Answer

Solution code:
N=int(input())
Bx=[]
By=[]
for i in range(N):
    a,b=map(int,input().split())
    Bx.append(a)
    By.append(b)
Rx=[]
Ry=[]
for i in range(N):
    c,d=map(int,input().split())
    Rx.append(c)
    Ry.append(d)
s=[]
t=[]
for i in range(N):
    for j in range(N):
        if Bx[j]<Rx[i] and By[j]<Ry[i]:
            a=(Bx[j],By[j])
            b=(Rx[i],Ry[i])
            s.append(a)
            t.append(b)
S=len(set(s))
T=len(set(t))
if S>T:
    print(T)
else:
    print(S)

Submission status: Wrong Answer

Solution code:
N=int(input())
Bx=[]
By=[]
for i in range(N):
    a,b=map(int,input().split())
    Bx.append(a)
    By.append(b)
print(Bx)
print(By)
Rx=[]
Ry=[]
for i in range(N):
    c,d=map(int,input().split())
    Rx.append(c)
    Ry.append(d)
print(Rx)
print(Ry)
s=[]
for i in range(N):
    for j in range(N):
        if Bx[i]<Rx[i] and By[i]<Ry[i]:
            a=(Bx[i],By[i])
            s.append(a)
print(s)
t=set(s)
print(len(t))

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])
blue.sort(key=lambda x:x[0])
res = 0
for i in range(len(blue)):
    index = -1
    maxy = -1
    for j in range(len(red)):
        if red[j][0] < blue[i][0]:
            if red[j][1] > maxy:
                maxy = red[j][1]
                index = j
    if index != -1:
        red.pop(index)
        res += 1
print(res)

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 x:x[1],reverse=True)

cnt = 0
for i in range(n):
    b.sort(reverse=True)
    B = []
    for j in range(n):
        if b[j][0] > r[i][0] and b[j][1] > r[i][1]:
            B.append([b[j][0] - r[i][0] + b[j][1] - r[i][1], b[j][0], b[j][1], j
])
    B.sort()
    if len(B) >= 1:
        cnt += 1
        b[B[0][3]][0] = -1
        b[B[0][3]][1] = -1

print(cnt)

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 x:x[1],reverse=True)

cnt = 0
for i in range(n):
    b.sort(reverse=True)
    B = []
    for j in range(n):
        if b[j][0] > r[i][0] and b[j][1] > r[i][1]:
            B.append([b[j][0] - r[i][0] + b[j][1] - r[i][1], b[j][0], b[j][1], j
])
    B.sort(reverse=True)    
    if len(B) >= 1:
        cnt += 1
        b[B[0][3]][0] = -1
        b[B[0][3]][1] = -1
    
print(cnt)

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 x:x[1],reverse=True)
B = []
for i in range(n):
    B.append([sum(b[i]),b[i][0],b[i][1]])
B.sort(reverse=True)

cnt = 0
for i in range(n):
    for j in range(n):
        if r[i][0] < B[j][1] and r[i][1] < B[j][2]:
            cnt += 1
            B[j][1] = -1
            B[j][2] = -1
            break
            
print(cnt)

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

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