Problem:


Score : 400 points

Problem Statement

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

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

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

Constraints

All input values are integers.

1 \leq N \leq 100

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

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

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

Input

Input is given from Standard Input in the following format:

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

Output

Print the maximum number of friendly pairs.

Sample Input 1

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

Sample Output 1

2

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

Sample Input 2

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

Sample Output 2

2

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

Sample Input 3

2
2 2
3 3
0 0
1 1

Sample Output 3

0

It is possible that no pair can be formed.

Sample Input 4

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

Sample Output 4

5

Sample Input 5

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

Sample Output 5

4



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


Sample output:
2

Submission status: Wrong Answer

Solution code:
n = int(input())
ab = [tuple(map(int, input().split())) for _ in range(n)]
cd = [tuple(map(int, input().split())) for _ in range(n)]
ab.sort(key=lambda x: (x[0], x[1]))
cd.sort(key=lambda x: (x[0], x[1]))
s = [0] * n

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

Submission status: Wrong Answer

Solution code:
from operator import itemgetter
N=int(input())
R=[list(map(int,input().split())) for n in range(N)]
B=[list(map(int,input().split())) for n in range(N)]

sorted(R,key=itemgetter(1),reverse=True)
B.sort()
ans=0

for c,d in B :
    for a,b in R :
        if a<c and b<d :
            ans+=1
            R.remove([a,b])
            break

print(ans)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter
N=int(input())
R,B,C=[],[],[]
for i in range(N) :
    a,b=map(int,input().split())
    R.append([a,b])

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

sorted(R,key=itemgetter(1),reverse=True)
sorted(B)
ans=0

for c,d in B :
    for a,b in R :
        if a<c and b<d :
            ans+=1
            R.remove([a,b])
            break


print(ans)

Submission status: Wrong Answer

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

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

cnt=0
s=0
F=[True]*N
for i in range(N):
    temp=[-1,-1]
    for j in range(N):
        if R[i][0]>=B[j][0]:continue
        else:
            if R[i][1]<B[j][1] and F[j]==True:
                if temp[0]<R[j][1]:
                    temp=[R[j][1],j]
    if temp[0]!=-1:
        cnt+=1
        F[temp[1]]=False
print(cnt)

Submission status: Wrong Answer

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

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

cnt=0
s=0
F=[True]*N
for i in range(N):
    for j in range(N):
        if R[i][0]>=B[j][0]:continue
        else:
            if R[i][1]<B[j][1] and F[j]==True:
                cnt+=1
                F[j]=False
                break
print(cnt)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter
def main():
    n = int(input())
    R = []
    g = [[0]*(2*n) for _ in range(2*n)]
    for _ in range(n):
        a,b  = map(int,input().split())
        R.append((a,b))
    for _ in range(n):
        c,d = map(int,input().split())
        g[d][c] = 1
    R.sort(key=itemgetter(1))
    ans = 0
    for i,j in R:
        f = 0
        for l in range(j+1,2*n):
            for k in range(i+1,2*n):
                if g[l][k]:
                    ans += 1
                    f = 1
                    g[l][k]=0
                    break
            if f:
                break
    print(ans)

main()

Submission status: Wrong Answer

Solution code:
from operator import itemgetter
def main():
    n = int(input())
    R = []
    B = []
    for _ in range(n):
        a,b  = map(int,input().split())
        R.append((a,b))
    for _ in range(n):
        c,d = map(int,input().split())
        B.append((c,d))
    R.sort(key=itemgetter(1))
    B.sort()
    ans = 0
    matched = set([])
    for i,j in R:
        for k,l in B:
            if i<k and j<l and ((k,l) not in matched):
                ans += 1
                matched.add((k,l))
                break
    print(ans)

main()

Submission status: Wrong Answer

Solution code:
N = int(input())
R = [[0, 0] for _ in range(N)]
B = [[0, 0] for _ in range(N)]
for i in range(N):
  R[i][0], R[i][1] = map(int, input().split())
for i in range(N):
  B[i][0], B[i][1] = map(int, input().split())
R.sort()
B.sort()
RF = [True for _ in range(N)]
BF = [True for _ in range(N)]
cnt = 0
for i in range(N):
  for j in range(N):
    if BF[j] == True:
      if R[i][0] < B[j][0] and R[i][1] < B[j][1]:
        cnt += 1
        RF[i] = False
        BF[j] = False
        break
print(cnt)

Submission status: Wrong Answer

Solution code:
n=int(input())
red1=sorted([list(map(int,input().split())) for i in range(n)],key=lambda x:x[1])
blue1=sorted([list(map(int,input().split())) for i in range(n)],key=lambda x:x[1])
red2=sorted(red1,key=lambda x:x[0])
blue2=sorted(blue1,key=lambda x:x[0])
cr1=[0]*n
cr2=[0]*n
for i in range(n):
    for j in range(n-1,-1,-1):
        if blue1[i][0]>red1[j][0] and blue1[i][1]>red1[j][1] and cr1[j]==0:
            cr1[j]=1
            break
for i in range(n):
    for j in range(n-1,-1,-1):
        if blue2[i][0]>red2[j][0] and blue2[i][1]>red2[j][1] and cr2[j]==0:
            cr2[j]=1
            break
#print(cr)
print(max(sum(cr1),sum(cr2)))

Submission status: Wrong Answer

Solution code:
n=int(input())
red=sorted([list(map(int,input().split())) for i in range(n)],key=lambda x:x[0]+x[1])
blue=sorted([list(map(int,input().split())) for i in range(n)],key=lambda x:x[0]+x[1])
cr=[0]*n
#print(red)
#print(blue)
for i in range(n):
    for j in range(n-1,-1,-1):
        if blue[i][0]>red[j][0] and blue[i][1]>red[j][1] and cr[j]==0:
            cr[j]=1
            break
#print(cr)
print(sum(cr))

Submission status: Wrong Answer

Solution code:
n = int(input())
al = [list(map(int, input().split())) for _ in range(n)]
bl =[list(map(int, input().split())) for _ in range(n)]

als = sorted(al)
bls = sorted(bl)

m=n
res = 0

for i in range(n):
    temp = als[i]
    for j in range(m):
        ttemp = bls[j]
        if ttemp[0] > temp[0] and ttemp[1] > temp[1]:
            res += 1 
            bls.pop(j)
            m -=1
            break

alss = sorted(al, key=lambda x: x[1])
blss = sorted(bl, key=lambda x: x[1])

ress = 0
m=n
for i in range(n):
    temp = alss[i]
    for j in range(m):
        ttemp = blss[j]
        if ttemp[0] > temp[0] and ttemp[1] > temp[1]:
            ress += 1 
            blss.pop(j)
            m -=1
            break

print(max(res,ress))

Submission status: Wrong Answer

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

from bisect import bisect_right
N = int(input())
ab = [list(mapint()) for _ in range(N)]
cd = [list(mapint()) for _ in range(N)]
ab.sort()
cd.sort(key=lambda x: x[1])
checked = [0]*N

ans = 0
for n in range(N):
    a, b = ab[n]
    for i in range(N):
        if checked[i]:
            continue
        c, d = cd[i]
        if a<=c and b<=d:
            ans += 1
            checked[i] = 1
            break

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

from bisect import bisect_right
N = int(input())
ab = [list(mapint()) for _ in range(N)]
cd = [list(mapint()) for _ in range(N)]
ab.sort()
cd.sort(key=lambda x: x[1])
checked = [0]*N

cdidx = 0
ans = 0
for n in range(N):
    a, b = ab[n]
    for i in range(N):
        if checked[i]:
            continue
        c, d = cd[i]
        if a<c and b<d:
            ans += 1
            checked[i] = 1
            break

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

from bisect import bisect_right
N = int(input())
ab = [list(mapint()) for _ in range(N)]
cd = [list(mapint()) for _ in range(N)]
ab.sort()
cd.sort(key=lambda x: x[1])
clis = [c for c, d in cd]
checked = [0]*N

cdidx = 0
ans = 0
for n in range(N):
    a, b = ab[n]
    cdidx = bisect_right(clis, a)
    if cdidx>=N:
        break
    for i in range(cdidx, N):
        if checked[i]:
            continue
        c, d = cd[i]
        if a<c and b<d:
            ans += 1
            checked[i] = 1
            break

print(ans)

Submission status: Wrong Answer

Solution code:
import sys


def resolve():
    readline = sys.stdin.readline    # 1行だけ文字列にする

    N = int(readline())

    # 赤，青点をx,y座標の2次元リストとして入力
    red = [list(map(int, readline().split())) for _ in [0] * N]
    blue = [list(map(int, readline().split())) for _ in [0] * N]

    # 青はy座標で降順ソート
    red.sort(key=lambda x: x[1], reverse=True)

    ans = 0
    for c, d in blue:
        for a, b in red:
            if a <= c and b <= d:
                ans += 1
                red.remove([a, b])
                break
    print(ans)


resolve()

Submission status: Wrong Answer

Solution code:
import sys


def resolve():
    readline = sys.stdin.readline    # 1行だけ文字列にする

    N = int(readline())
    NN = 2 * N + 1

    # 青色はx座標をlistのindex,y座標をlistのvalueとして入力，赤は逆
    red = [[] for _ in [0] * NN]
    blue = [[] for _ in [0] * NN]
    for _ in [0] * N:
        a, b = map(int, readline().split())
        red[b].append(a)
    for _ in [0] * N:
        c, d = map(int, readline().split())
        blue[c].append(d)

    # 青色でvalueのy座標について降順(大きい順)でソート
    # 赤色ではvalueのx座標について降順でソート
    # これで青色はx座標は昇順(index)，y座標は降順(value)にソートされる
    # 赤色はy座標が昇順(index)，x座標が降順(value)
    for i in range(NN):
        r = red[i]
        b = blue[i]
        r.sort(reverse=True)
        b.sort(reverse=True)
        r[0:0] = [i]
        b[0:0] = [i]

    # 青点はx座標の昇順で，赤点はy座標の降順
    # 最小のxの青点で最大のyを持つ赤点を選択
    ans = 0
    flag = False
    while blue:
        cd_blue = blue.pop(0)
        c = cd_blue.pop(0)
        if cd_blue:
            for d in cd_blue:
                for ba_red in red[::-1]:
                    b = ba_red[0]
                    if ba_red[1:]:
                        for i in range(1, len(ba_red)):
                            a = ba_red[i]
                            if a <= c and b <= d:
                                ans += 1
                                del red[b][i]
                                flag = True
                                break
                        if flag:
                            break
                if flag:
                    flag = False
                    break
    print(ans)


# resolve()

Submission status: Wrong Answer

Solution code:
import sys
def input(): return sys.stdin.readline().strip()


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

    """
    解説pdfの通り、x方向に見た上で青い点に対応する赤い点の最適な物を貪欲に選べば良い。
    これが最適であることの証明は、非最適なペアリングを上述のペアリングに「「１組」」繋ぎ直しても
    ペアの個数が減らないことを見れば良い。
    （x+yが小さい順に見ればいけるかなと想定したのが外れルート。。。）
    """

    ans = 0
    for c, d in blue:
        cand = (-1, -1)
        for a, b in red:
            if a < c and b < d and cand[1] < b and (a, b) not in red_fin:
                cand = (a, b)
        if cand == (-1, -1): continue
        ans += 1
        red_fin.add(cand)
    print(ans)





if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
def input(): return sys.stdin.readline().strip()


def main():
    N = int(input())
    red = []
    for _ in range(N):
        a, b = map(int, input().split())
        red.append((min(a, b), a, b))
    red.sort(key = lambda x: (x[0], x[1]))
    red_fin = set()
    blue = []
    for _ in range(N):
        c, d = map(int, input().split())
        blue.append((min(c, d), c, d))
    blue.sort(key = lambda x: (x[0], x[1]))
    #print(blue)
    #print(red)

    ans = 0
    for n, c, d in blue:
        for m, a, b in red:
            if a < c and b < d and (m, a, b) not in red_fin:
                ans += 1
                red_fin.add((m, a, b))
                #print("({}, {}, {})---({}, {}, {})".format(n,c,d,m,a,b))
                break
    print(ans)





if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
import heapq
import re
from itertools import permutations
from bisect import bisect_left, bisect_right
from collections import Counter, deque
from math import factorial, sqrt, ceil, gcd
from functools import lru_cache, reduce
from decimal import Decimal
from operator import mul

INF = 1 << 60
MOD = 1000000007
sys.setrecursionlimit(10 ** 7)


# UnionFind
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

# ダイクストラ
def dijkstra_heap(s, edge, n):
    #始点sから各頂点への最短距離
    d = [10**20] * n
    used = [True] * n #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d

# 素因数分解
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

# 組合せnCr
def combinations_count(n, r):
    if n < r:
        return 0
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom

# 2数の最小公倍数
def lcm(x, y):
    return (x * y) // gcd(x, y)

# リストの要素の最小公倍数
def lcm_list(numbers):
    return reduce(lcm, numbers, 1)

# リストの要素の最大公約数
def gcd_list(numbers):
    return reduce(gcd, numbers)

# 素数判定
def is_prime(n):
    if n <= 1:
        return False
    p = 2
    while True:
        if p ** 2 > n:
            break
        if n % p == 0:
            return False
        p += 1
    return True


# limit以下の素数を列挙
def eratosthenes(limit):
    A = [i for i in range(2, limit+1)]
    P = []

    while True:
        prime = min(A)
        
        if prime > sqrt(limit):
            break
            
        P.append(prime)
            
        i = 0
        while i < len(A):
            if A[i] % prime == 0:
                A.pop(i)
                continue
            i += 1
            
    for a in A:
        P.append(a)
            
    return P

# 同じものを含む順列
def permutation_with_duplicates(L):

    if L == []:
        return [[]]

    else:
        ret = []

        # set（集合）型で重複を削除、ソート
        S = sorted(set(L))

        for i in S:

            data = L[:]
            data.remove(i)

            for j in permutation_with_duplicates(data):
                ret.append([i] + j)

        return ret

def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]



# ここから書き始める
n = int(input())
a = [0 for i in range(n)]
b = [0 for i in range(n)]
c = [0 for i in range(n)]
d = [0 for i in range(n)]
for i in range(n):
    a[i], b[i] = map(int, input().split())
for i in range(n):
    c[i], d[i] = map(int, input().split())

x = sorted([[a[i], b[i]] for i in range(n)], reverse=True, key=lambda x:(x[0], x[1]))
y = sorted([[c[i], d[i]] for i in range(n)], key=lambda x:(x[0], x[1]))

# print("x =", x)
# print("y =", y)
# x_used = [0 for i in range(n)]
y_used = [0 for i in range(n)]

ans = 0
for i in range(n):
    for j in range(n):
        if y_used[i] == 1:
            continue
        a = x[i][0]
        b = x[i][1]
        c = y[j][0]
        d = y[j][1]
        if a < c and b < d:
            ans += 1
            # x_used[i] = 1
            y_used[j] = 1
            break
print(ans)

Submission status: Wrong Answer

Solution code:
import sys


def resolve():
    readline = sys.stdin.readline    # 1行だけ文字列にする

    N = int(readline())
    red = [list(map(int, readline().split())) for _ in [0] * N]
    blue = [list(map(int, readline().split())) for _ in [0] * N]

    # 両色でx座標について降順(大きい順)でソート
    red.sort(reverse=True)
    blue.sort(reverse=True)

    # 各青点を降順に見て，赤点を降順に見て条件を満たすか判定
    ans = 0
    while blue:
        c, d = blue.pop(0)
        for i in red:
            a, b = i
            if a < c and b < d:
                ans += 1
                red.remove(i)
                break
    print(ans)


resolve()

Submission status: Wrong Answer

Solution code:
import sys


def resolve():
    readline = sys.stdin.readline    # 1行だけ文字列にする

    N = int(readline())
    red = [list(map(int, readline().split())) for _ in [0] * N]
    blue = [list(map(int, readline().split())) for _ in [0] * N]

    # 各点の原点からの距離を計算しindex0に挿入し，昇順でソート
    for i in range(N):
        red[i][0:0] = [red[i][0] ** 2 + red[i][1] ** 2]
        blue[i][0:0] = [blue[i][0] ** 2 + blue[i][1] ** 2]
    red.sort(reverse=True)
    blue.sort(reverse=True)

    ans = 0
    while blue:
        _, c, d = blue.pop(0)
        for i in red:
            _, a, b = i
            if a < c and b < d:
                ans += 1
                red.remove(i)
                break
    print(ans)


resolve()

Submission status: Wrong Answer

Solution code:
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)]
Done = [True] * N
Red.sort(reverse= True)
Blue.sort()
Bluex = []
Bluey = []
ans = 0
for x, y in Blue:
    Bluex.append(x)
    Bluey.append(y)

for x, y in Red:
    i = bisect.bisect_right(Bluex, x)
    for j in range(i, N)[::-1]:
        if y < Bluey[j] and Done[j]:
            ans += 1
            Done[j] = False
            break
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

sys.setrecursionlimit(10000000)

N = int(input())
AB = []
CD = []

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

for i in range(N):
    C, D = map(int, input().split())
    CD.append((C, D))

AB.sort()
CD.sort()

used = [False] * N
cnt = 0

for i in range(N):
    m = -1
    for j in range(N):
        if CD[i][0] > AB[j][0] and CD[i][1] > AB[j][1]:
            if m < 0 or AB[m][1] < AB[j][1]:
                m = j

    if m >= 0:
        used[m] = True
        cnt += 1

print(cnt)

Submission status: Wrong Answer

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


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

  num_friends = 0

  for ib, b in enumerate(B):
    bx, by = b[0], b[1]

    tmp_r = (-1, -1)

    for ir, r in enumerate(R):
      rx, ry = r[0], r[1]

      if rx < bx and \
         ry < by and \
         tmp_r[1] < ry:
         # b[0] - r[0] < tmp_b[0] - r[0] and \
         # b[1] - r[1] < tmp_b[1] - r[1]:
        tmp_r = r

    if tmp_r == (-1, -1):
      continue
    num_friends += 1
    R.remove(tmp_r)

  print(num_friends)


if(__name__ == '__main__'):
  main()

Submission status: Wrong Answer

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


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

  cnt = {}
  for i, ri in enumerate(R):
    ai, bi = ri[0], ri[1]
    tmp_cnt = 0
    for j, rj in enumerate(R):
      aj, bj = rj[0], rj[1]
      if i == j:
        continue
      if ai < aj and bi < bj:
        tmp_cnt += 1
    cnt[ri] = tmp_cnt

  # print(cnt)
  R = sorted(R, key=lambda x: cnt[x])

  num_friends = 0

  for ir, r in enumerate(R):

    tmp_b = (float('inf'), float('inf'))

    for ib, b in enumerate(B):

      if r[0] < b[0] and \
         r[1] < b[1] and \
         (b[0] - r[0]) + (b[1] - r[1]) < (tmp_b[0] - r[0]) + (tmp_b[1] - r[1]):
         # b[0] - r[0] < tmp_b[0] - r[0] and \
         # b[1] - r[1] < tmp_b[1] - r[1]:
        tmp_b = b

    if tmp_b == (float('inf'), float('inf')):
      continue
    num_friends += 1
    B.remove(tmp_b)

  print(num_friends)


if(__name__ == '__main__'):
  main()

Submission status: Wrong Answer

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


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

  R = reversed(sorted(R, key=lambda x: x[0]+x[1]))

  num_friends = 0

  for ir, r in enumerate(R):

    tmp_b = (float('inf'), float('inf'))

    for ib, b in enumerate(B):

      if r[0] < b[0] and \
         r[1] < b[1] and \
         (b[0] - r[0]) + (b[1] - r[1]) < (tmp_b[0] - r[0]) + (tmp_b[1] - r[1]):
         # b[0] - r[0] < tmp_b[0] - r[0] and \
         # b[1] - r[1] < tmp_b[1] - r[1]:
        tmp_b = b

    if tmp_b == (float('inf'), float('inf')):
      continue
    num_friends += 1
    B.remove(tmp_b)

  print(num_friends)


if(__name__ == '__main__'):
  main()

Submission status: Wrong Answer

Solution code:

from collections import deque
N = int(input())
Y = {}
for _ in range(N):
    c,d = map(int,input().split())
    Y[c] = d  
X = []
for _ in range(N):
    a,b = map(int,input().split())
    X.append([a,b])

X.sort()
dq = deque(X)
cnt =0
print(X)
while dq:
    x,y = dq.popleft()
    sorted_Y = sorted(Y.items(),reverse=True, key = lambda x:x[1])
    print(sorted_Y)
    for key,val in sorted_Y:
        if key <x and val<y:
            cnt += 1
            del Y[key]
            break
    
print(cnt)

Submission status: Wrong Answer

Solution code:

from collections import deque
N = int(input())
Y = {}
for _ in range(N):
    c,d = map(int,input().split())
    Y[c] = d  
X = []
for _ in range(N):
    a,b = map(int,input().split())
    X.append([a,b])

X.sort()
dq = deque(X)
cnt =0
while dq:
    x,y = dq.popleft()
    sorted_Y = sorted(Y.items(),reverse=True, key = lambda x:x[1])
    for key,val in sorted_Y:
        if key <x:
            cnt += 1
            del Y[key]
            break
    
print(cnt)

Submission status: Wrong Answer

Solution code:

N = int(input())
Y = {}
for _ in range(N):
    c,d = map(int,input().split())
    Y[c] = d  
X = []
for _ in range(N):
    a,b = map(int,input().split())
    X.append([a,b])
  
X.sort()
cnt =0
while X:
    x,y = X[0]
    del X[0]
    sorted_Y = sorted(Y.items(),reverse=True, key = lambda x:x[1])
    for key,val in sorted_Y:
        if key <x:
            cnt += 1
            del Y[key]
            break
    
print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
AB = [list(map(int,input().split())) for _ in range(N)]
CD = [list(map(int,input().split())) for _ in range(N)]
CDC1 = [[] for i in range(N)]
for i in range(N):
    for j in range(N):
        if AB[i][0] < CD[j][0] and AB[i][0] < CD[j][0]:
            CDC1[i].append(j)
CDC2 = list(CDC1)
CDC3 = sorted(list(CDC2),key=lambda x: len(x))
count = 0
while len(CDC3)>0:
    if len(CDC3[0])>0:
        tmp = CDC3[0][0]
        count += 1
        CDC3.pop(0)
        for cdc in CDC3:
            if tmp in cdc:
                pass
                cdc.pop(cdc.index(tmp))
    else:
        CDC3.pop(0)

print(count)

Submission status: Wrong Answer

Solution code:
# input
N = int(input())
AB = sorted([tuple(map(int, input().split())) for i in range(N)], key=lambda x: x[0] + x[1], reverse=True)
CD = [tuple(map(int, input().split())) for j in range(N)]

# check
cnt = 0
for a, b in AB:
    pair = sorted([(c, d) for c, d in CD if a < c and b < d], key=lambda x: x[0] + x[1])
    if not pair:
        continue

    CD.remove(pair[0])
    cnt += 1

print(cnt)

Submission status: Wrong Answer

Solution code:
# input
N = int(input())
AB = sorted([tuple(map(int, input().split())) for i in range(N)], key=lambda x: x[0] + x[1], reverse=True)
CD = [tuple(map(int, input().split())) for i in range(N)]

# check
cnt = 0
for a, b in AB:
    pair = [(c, d) for c, d in CD if a < c and b < d]
    if not pair:
        continue

    CD.remove(min(pair))
    cnt += 1

print(cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [list(map(int, input().split())) for _ in range(n)]
b = [list(map(int, input().split())) for _ in range(n)]
x = []
for i,j in a:
    x.append((i,j,1))
for i,j in b:
    x.append((i,j,2))
x.sort()
#print(x)
for i in range(2*n):
    x[i] = (x[i][1],x[i][2])
#print(x)
ans = 0
while len(x):
    maxindex = 0
    maxvalue = -1
    for i in range(len(x)):
        if x[i][0]>maxvalue:
            maxvalue = x[i][0]
            maxindex = i
    if (x[maxindex][1]==1):
        x.pop(i)
    else:
        maxindex2 = 0
        maxvalue2 = -1
        for i in range(maxindex):
            if (x[i][1]==1):
                if (x[i][0]>maxvalue2):
                    maxvalue2 = x[i][0]
                    maxindex2 = i
        if (maxvalue2!=-1):
            #print(maxindex,maxindex2,x)
            x.pop(maxindex)
            x.pop(maxindex2)
            ans += 1
        else:
            x.pop(maxindex)
print(ans)

Submission status: Wrong Answer

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

used = []
for i in range(N):
    c, d = blue[i]
    m = float("INF")
    tmp = -1
    for j in range(N):
        if j in used:
            continue
        a, b = red[j]
        if a < c and b < d:
            dx = c - a
            dy = d - b
            if m > dx + dy:
                m = dx + dy
                tmp = j
    if tmp != -1:
        used.append(tmp)
print(len(used))

Submission status: Wrong Answer

Solution code:
def c_2d_plane_2n_points_bipartite_graph():
    import networkx as nx
    from networkx.algorithms.flow import dinitz
    N = int(input())
    Red_point_pos = [[int(i) for i in input().split()] for j in range(N)]
    Blue_point_pos = [[int(i) for i in input().split()] for j in range(N)]

    # 1 から N 番を赤い点に割り当て，N+1 番から 2N 番を青い点に割り当てる
    # ソースを 0 番とし，シンクを 2N+1 番とする
    graph = nx.DiGraph()
    graph.add_nodes_from(range(2 * N + 2))
    for i in range(N):
        for j in range(N):
            a, b = Red_point_pos[i]
            c, d = Blue_point_pos[j]
            if a < c and b < d:  # i 番の赤い点と j 番の青い点はペアにできうる
                graph.add_edge(i + 1, j + N + 1, capacity=1)
                graph.add_edge(j + N + 1, i + 1, capacity=1)
    for i in range(1, N + 1):
        graph.add_edge(0, i, capacity=1)
    for j in range(N + 1, 2 * N + 1):
        graph.add_edge(j, 2 * N + 1, capacity=1)
    return dinitz(graph, 0, 2 * N + 1).graph['flow_value']

print(c_2d_plane_2n_points_bipartite_graph())

Submission status: Wrong Answer

Solution code:
n = int(input())
class Cumulative_Sum_2D:
    def __init__(self, a):
        lai = len(a)
        laj = len(a[0])
        self.s = [[0] * (laj + 1) for _ in range(lai + 1)]
        for i in range(lai):
            for j in range(laj):
                self.s[i+1][j+1] = self.s[i+1][j] + a[i][j]
        for i in range(lai):
            for j in range(laj):
                self.s[i+1][j+1] += self.s[i][j+1]
    def sum(self, li, lj, ri, rj):
        s = self.s
        return s[ri][rj] - s[li][rj] - s[ri][lj] + s[li][lj]

size = (2 * n + 2)
ab = [[0] * size for _ in range(size)]
cd = [[0] * size for _ in range(size)]
ablist = []
cdlist = []

for _ in range(n):
    xi, yi = map(int, input().split())
    ab[xi][yi] += 1
    ablist.append((xi,yi))
for _ in range(n):
    xi, yi = map(int, input().split())
    cd[xi][yi] += 1
    cdlist.append((xi,yi))
csab = Cumulative_Sum_2D(ab)
cscd = Cumulative_Sum_2D(cd)
#import numpy as np
#print(np.array(csab.s))
#print(np.array(cscd.s))
ans = 0
"""
for ci,di in cdlist:
    if cscd.sum(0,0,ci+1,di+1) <= csab.sum(0,0,ci+1,di+1):
        ans += 1
    print(ci,di,cscd.sum(0,0,ci+1,di+1) ,csab.sum(0,0,ci+1,di+1))
print(ans)
"""
ans2 = 0
for ai,bi in cdlist:
    if cscd.sum(ai,bi, size, size) == 0:
        ans2 += 1
    #print(ai,bi,cscd.sum(ai,bi, size, size) , csab.sum(ai,bi, size, size))

print(n - ans2)