Problem: 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.

Submission attempts (in order):
import sys
import math
from collections import deque
import bisect

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def make_grid(h, w, num): return [[int(num)] * w for _ in range(h)]


def main():
	N = NI()
	R = [NLI() for _ in range(N)]
	B = {}
	for i in range(N):
		c, d = NMI()
		B[c] = d
	R.sort(key=lambda x: x[0], reverse=True)
	ans = 0
	for r in R:
		print(r)
		BX = sorted(list(B.keys()))
		idx = bisect.bisect_left(BX, r[0])

		tmp_by = 300
		tmp_bx = -1
		for bx in BX[idx:]:
			if B[bx] < tmp_by:
				tmp_by = B[bx]
				tmp_bx = bx
		if tmp_bx != -1:
			print(tmp_bx, B[tmp_bx])
			del B[tmp_bx]
			ans += 1

	print(ans)





if __name__ == "__main__":
	main()

import sys
import math
from collections import defaultdict
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
INF = 10 ** 20
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


class Dinic:
    


    def __init__(self, n):
        self.n = n
        self.links = [[] for _ in range(n)]
        self.depth = None
        self.progress = None

    def add_link(self, _from, to, cap):
        self.links[_from].append([cap, to, len(self.links[to])])
        self.links[to].append([0, _from, len(self.links[_from]) - 1])

    def bfs(self, s):
        from collections import deque

        depth = [-1] * self.n
        depth[s] = 0
        q = deque([s])
        while q:
            v = q.popleft()
            for cap, to, rev in self.links[v]:
                if cap > 0 and depth[to] < 0:
                    depth[to] = depth[v] + 1
                    q.append(to)
        self.depth = depth

    def dfs(self, v, t, flow):
        if v == t:
            return flow
        links_v = self.links[v]
        for i in range(self.progress[v], len(links_v)):
            self.progress[v] = i
            cap, to, rev = link = links_v[i]
            if cap == 0 or self.depth[v] >= self.depth[to]:
                continue
            d = self.dfs(to, t, min(flow, cap))
            if d == 0:
                continue
            link[0] -= d
            self.links[to][rev][0] += d
            return d
        return 0

    def max_flow(self, s, t):
        flow = 0
        while True:
            self.bfs(s)
            if self.depth[t] < 0:
                return flow
            self.progress = [0] * self.n
            current_flow = self.dfs(s, t, INF)
            while current_flow > 0:
                flow += current_flow
                current_flow = self.dfs(s, t, INF)


def main():
    N = NI()
    R = [NLI() for _ in range(N)]
    B = [NLI() for _ in range(N)]
    din = Dinic(2*N+2)
    for a, b in R:
        for c, d in B:
            if a >= c or b >= d: continue
            din.add_link(a, c, 1)
    for a, b in R:
        din.add_link(2*N, a, 1)
    for c, d in B:
        din.add_link(c, 2*N+1, 1)
    print(din.max_flow(2*N, 2*N+1))



if __name__ == "__main__":
    main()

Verdicts: Wrong Answer

Accepted