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:
def main():
    N = int(input())
    AB = [list(map(int, input().split())) for _ in [0] * N]
    CD = [list(map(int, input().split())) for _ in [0] * N]

    red = sorted(AB, key=lambda x: x[1])
    blue = sorted(CD, key=lambda x: x[1])
    red.sort(reverse=1)
    blue.sort(reverse=1)

    dist = 0
    pair = (500, 500)
    ans = 0
    for a, b in red:
        for i, (c, d) in enumerate(blue):
            if all((a <= c, b <= d, c < 500, d < 500)):
                dist = abs(a - c) + abs(b - d)
                pair = min(pair, (dist, i))
        if pair != (500, 500):
            blue[pair[1]] = (500, 500)
            pair = (500, 500)
            ans += 1
    print(ans)

main()

Submission status: Wrong Answer

Solution code:
red = list()
blue = list()
n = int(raw_input())
for i in range(0,n):
    red.append(map(int,raw_input().split()))
for i in range(0,n):
    blue.append(map(int, raw_input().split()))

red.sort(key=lambda x:x[0]+x[1])
blue.sort(key=lambda x:x[0]+x[1])

red = red[::-1]
blue = blue[::-1]
c = int()
for r in red:
    for (i,b) in enumerate(blue):
        if r[0]<b[0] and r[1]<b[1]:
            print r, b
            c+=1
            blue.pop(i)
            break
print c

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 i in range(n)]
ans=0
for i in range(n):
    plus=0
    res=float("inf")
    for j in range(len(b)): #一番もっともなのを探す
        if b[j][0]-r[i][0]>0 and b[j][1]-r[i][1]>0:
            if b[j][0]-r[j][0]+b[j][1]-r[j][1]<res:
                res=b[j][0]-r[j][0]+b[j][1]-r[j][1]
                delb=j
            plus=1
    ans+=plus
    if plus==1: b.pop(delb)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(raw_input())

red = []
blue = []

for a in range(n):
  q = map(int,raw_input().split(" "))
  red.append(q)

for a in range(n):
  q = map(int,raw_input().split(" "))
  blue.append(q)

red.sort()
blue.sort()
G = []
for a in range(n):
  G.append([])

used = [0]*n
match = [-1]*n

def add_edge(u,v):
  global G
  G[u].append(v)

def dfs(v):
  global G,match,used
  used[v] = 1
  for i in range( len(G[v]) ):
    u = G[v][i]
    w = match[u]
    if w < 0 or (used[w] != 1) and dfs(w) == 1:
      #match[v] = u
      match[u] = v
      return 1
  return 0

for a in range(n):
  for b in range(n):
    if red[a][0] < blue[b][0] and red[a][1] < blue[b][1]:
      add_edge(a,b)

ans = 0
for a in range(n):
  if match[a] < 0:
    used = [0]*n
    if dfs(a) == 1:
      ans += 1
print ans

Submission status: Wrong Answer

Solution code:
def re_count(x):
    c={}
    for values in x.values():
        c.setdefault(values,0)
        c[values]=1+c[values]
    v=0
    for keys in c:
        v+=min(keys,c[keys])
    return v

N=int(input())
a=[]
b=[]
for i in range(N):
    x,y=input().split()
    a.append(int(x))
    b.append(int(y))
c=[]
d=[]
for i in range(N):
    x,y=input().split()
    c.append(int(x))
    d.append(int(y))
    
num_a={}
num_c={}
for j in range(N):
    for i in range(N):
        if a[j]<c[i] and b[j]<d[i]:
            num_a.setdefault(a[j],0)
            num_a[a[j]]+=1
            num_c.setdefault(c[i],0)
            num_c[c[i]]+=1
            
a=re_count(num_a)
c=re_count(num_c)
        
print(min(a,c))

Submission status: Wrong Answer

Solution code:
N = int(input())

aka_l = []
ao_l = []

for i in range(N):
    x,y = map(int, input().split())
    z = x*y
    aka_l.append([x,y,z])

for i in range(N):
    x,y = map(int, input().split())
    z = x*y
    ao_l.append([x,y,z])

print(aka_l)
print(ao_l)

sorted(aka_l, key = lambda m:m[2])
sorted(ao_l, key = lambda m:m[2])

aka_l

cnt = 0
for blue in ao_l:
    for red in aka_l:
        if red[4:] != 1:
            if blue[4:] != 1:
                if (red[0] > blue[0]) and (red[1] > blue[1]) and (red[2] > blue[2]):
                    cnt += 1
                    red.append(1)
                    blue.append(1)

print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
block = [['' for x in range(2*N)] for y in range(2*N)]
for i in range(N):
    tmp = input().split()
    block[int(tmp[0])][int(tmp[1])] = 'R'
for j in range(N):
    tmp = input().split()
    block[int(tmp[0])][int(tmp[1])] = 'B'

queue =[]
count = 0
for i in range(2*N):
    for j in range(2*N):
        if block[i][j] =='R':
            queue.append([i,j])
        elif block[i][j] == 'B' and len(queue) > 0:
            L = len(queue)
            for k in range(L):
                if queue[k][0] < i and queue[k][1] < j:
                    block[i][j] = ''
                    queue.pop(k)
                    count += 1
                    break
print(count)

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input().strip())
ab = [list(map(int, input().strip().split(" "))) for _ in range(n)]
cd = [list(map(int, input().strip().split(" "))) for _ in range(n)]
ab = sorted(ab, key=lambda x: x[1])
ab = sorted(ab, key=lambda x: x[0])
cd = sorted(cd, key=lambda x: x[1])
cd = sorted(cd, key=lambda x: x[0])
mat = [[0 for _ in range(n)] for _ in range(n)]
for i, _ab in enumerate(ab):
    for j, _cd in enumerate(cd):
        if _ab[0] < _cd[0] and _ab[1] < _cd[1]:
            mat[i][j] = 1
mat = sorted(mat, key=lambda x: sum(x))
mat = np.array(mat)
ind = set([])
for _mat in mat:
    iii = np.where(_mat > 0)[0]
    for _i in iii:
        if _i not in ind:
            ind.add(_i)
            break
print(len(ind))

Submission status: Wrong Answer

Solution code:
n = int(input())
data = [0, 0, True] * n
ans = 0
for i in range(0, n):
    line = list(map(int, input().split(" ")))
    data[line[0]] = [line[1], 0, True]
for i in range(0, n):
    line = list(map(int, input().split(" ")))
    data[line[0]] = [line[1], 1, True]
for i in range(0, n):
    kappuru = 0
    if data[i][2]:
        for j in range(i + 1, n*2):
            if data[j][2] and data[i][1] != data[j][1]:
                if data[i][1]==0:
                    if data[i][0] < data[j][0]:
                        if kappuru == 0:
                            kappuru = j
                        elif data[j][0] < data[kappuru][0]:
                            kappuru = j
                else:
                    if data[i][0] > data[j][0]:
                        if kappuru == 0:
                            kappuru = j
                        elif data[j][0] > data[kappuru][0]:
                            kappuru = j
        if kappuru != 0:
            data[i][2] = False
            data[kappuru][2] = False
            ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
red_list = []
x_min = 200
for i in range(n):
    x, y = map(int, input().split())
    x_min = min(x_min, x)
    red_list.append((x, y))
red_list = sorted(red_list)
blue_list = []
for i in range(n):
    x, y = map(int, input().split())
    if x_min < x:
        blue_list.append((x, y))
blue_list = sorted(blue_list, key=lambda x: max(x[0], x[1]))

max_pair = min(len(red_list), len(blue_list))
pair = 0
for blue in blue_list:
    flag = 0
    p_x, p_y = 200, 200
    for red in red_list:
        if blue[0] > red[0] and blue[1] > red[1]:
            if p_x + p_y > (blue[0]-red[0]) + (blue[1]-red[1]):
                p_x = red[0]
                p_y = red[1]
                flag = 1
    if flag == 1:
        pair += 1
        red_list.remove((p_x, p_y))
    if pair >= max_pair:
        break

print(pair)

Submission status: Wrong Answer

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

import numpy as np
n = int(input().strip())
ab = [list(map(int, input().strip().split(" "))) for _ in range(n)]
cd = [list(map(int, input().strip().split(" "))) for _ in range(n)]
ab = sorted(ab, key=lambda x: x[1])
ab = sorted(ab, key=lambda x: x[0])
cd = sorted(cd, key=lambda x: x[1])
cd = sorted(cd, key=lambda x: x[0])
mat = [[0 for _ in range(n)] for _ in range(n)]
for i, _ab in enumerate(ab):
    for j, _cd in enumerate(cd):
        if _ab[0] < _cd[0] and _ab[1] < _cd[1]:
            mat[i][j] = 1
mat = sorted(mat, key=lambda x: sum(x))
mat = np.array(mat)
print(mat)
ind = set([])
for _mat in mat:
    iii = np.where(_mat > 0)[0]
    for _i in iii:
        if _i not in ind:
            ind.add(_i)
print(len(ind))

Submission status: Wrong Answer

Solution code:
from collections import deque
import sys
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline


def get_pair_list(ax_list, red_already_pair_list, blue_already_pair_list):
    is_search_blue = True
    pair_list = set([])
    pair_wait_list = deque([])
    for i in range(len(ax_list)):
        if ax_list[i][2] == 'b' and ax_list[i][1] not in blue_already_pair_list:
            pair_wait_list.append(ax_list[i][1])

        if ax_list[i][2] == 'r' and ax_list[i][1] not in red_already_pair_list:
            pair_red = ax_list[i][1]
            if len(pair_wait_list) != 0:
                for pair_blue in pair_wait_list:
                    pair_list.add((pair_red, pair_blue))

    return pair_list



def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N] = [int(input_raw[0])]
    red_list = []
    blue_list = []
    for i in range(N):
        input_raw = read_func().strip().split()
        red_list.append((int(input_raw[0]), int(input_raw[1])))

    for i in range(N):
        input_raw = read_func().strip().split()
        blue_list.append((int(input_raw[0]), int(input_raw[1])))


    x_ax_list = []
    y_ax_list = []
    for i in range(N):
        x_ax_list.append((red_list[i][0], i + 1, 'r'))
        x_ax_list.append((blue_list[i][0], i + 1, 'b'))
        y_ax_list.append((red_list[i][1], i + 1, 'r'))
        y_ax_list.append((blue_list[i][1], i + 1, 'b'))


    x_ax_list.sort(reverse= True)
    y_ax_list.sort(reverse= True)

    x_pair_list = get_pair_list(x_ax_list,[],[])
    y_pair_list = get_pair_list(y_ax_list,[],[])

    pair_list = (x_pair_list & y_pair_list)
    x_already_list = set([])
    y_already_list = set([])
    count = 0
    for pair in (pair_list):
        if pair[0] not in x_already_list and pair[1]  not in y_already_list:
            count += 1
            x_already_list.add(pair[0])
            y_already_list.add(pair[1])

    print count

    


if __name__ == '__main__':
    main()

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

cand = []
for b in B:
    temp = []
    for i, r in enumerate(R):
        if r[0] < b[0] and r[1] < b[1]:
            temp.append(i)
    cand.append(temp)

cand = sorted(cand, key=lambda x: len(x))

result = 0
d = [False for _ in range(N)]
while True:
    flag = False
    for c in cand:
        if len(c) == 1:
            flag = True
    cnt = d.count(True)

    if flag:
        for j, c in enumerate(cand):
            if 0 < len(c):
                num = c[0]
                if len(c) == 1 and not d[num]:
                    result += 1
                    d[num] = True
                    for i, e in enumerate(cand):
                        if num in e:
                            cand[i].remove(num)
                cand[j] = []
                break
    else:
        cnt = [0 for _ in range(N)]
        for c in cand:
            for i in range(N):
                cnt[i] += c.count(i)
        flag = False
        for i in range(N):
            if cnt[i] == 1:
                idx = i
                flag = True
                break

        if flag:
            num = idx
            result += 1
            d[num] = True
            for i, c in enumerate(cand):
                if num in c:
                    cand[i] = []
        else:
            cnt = d.count(True)
            for j, c in enumerate(cand):
                if 0 < len(c):
                    num = c[0]

                    result += 1
                    d[num] = True
                    for i, e in enumerate(cand):
                        if num in e:
                            cand[i].remove(num)
                    cand[j] = []
                    break

    if cnt == d.count(True):
        break

print(result)

Submission status: Wrong Answer

Solution code:
N=int(input())
Red=[[0,0,0]]*N

for i in range(N):
	a,b=input().split()
	#Red[i] = [(int(a)+int(b)),int(a),int(b)]
	Red[i] = [int(a),int(b)]

Blue=[[0,0,0]]*N
for i in range(N):
	a,b=input().split()
	#Blue[i]=[(int(a)+int(b)),int(a),int(b)]
	Blue[i]=[int(a),int(b)]

Red.sort()
Blue.sort()

#print("R:{}".format(Red))
#print("B:{}".format(Blue))

ans=0
for i in range(N):
	for l in range(N):
		for k in range(N):
			if Blue[k][0] == Red[i][0] + l or Blue[k][1] == Red[i][1] + l:
				if Red[i][0] < Blue[k][0] and Red[i][1] < Blue[k][1]:
					#print("R:{},B:{}".format(Red[i],Blue[k]))
					ans += 1
					Blue[k][0] = 0
					Red[i][0] = Blue[N-1][0]+1
					#print("R:{}".format(Red))
					#print("B:{}".format(Blue))
print(ans)

Submission status: Wrong Answer

Solution code:
def abc091_c():
    from operator import itemgetter
    _reds = []
    _blues = []
    _count = 0

    _n = int(input())

    for i in range(_n):
        _instr = str(input()).split()
        _reds.append(list(map(int, _instr)))

    for i in range(_n):
        _instr = str(input()).split()
        _blues.append(list(map(int, _instr)))

    _reds.sort()
    _blues.sort(key=itemgetter(1))

    for i in range(len(_reds)):
        _num = 0
        _blue2=[]
        while _reds[i][1] < _blues[_num][1]:
            _blue2.append(_blues[_num])
            _num += 1
        _blue2.sort()
        if len(_blue2) > 0:
            if _reds[i][0] < _blue2[0][0]:
                _count += 1
                _blues.remove(_blue2[0])
        """for j in range(len(_blues)):
            if _reds[i][0] >= _blues[j][0]:
                continue
            elif _reds[i][1] < _blues[j][1]:
                _count += 1
                del _blues[j]
                break
            else:
                continue"""
    print(_count)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[]
b=[]
for i in range(n):
    a.append(list(map(int,input().split())))
for i in range(n):
    b.append(list(map(int,input().split())))
an=sorted(a, key=lambda x:(x[0],x[1]),reverse=True)
bn=sorted(b, key=lambda x:(x[0],x[1]),reverse=True)
count=0
for i in range(len(bn)):
    for j in range(len(an)):
#        print(an[j],bn[i])
        if bn[i][0]>an[j][0] and bn[i][1]>an[j][1]:
            count+=1
            an.pop(j)
            break
 
print(count)

Submission status: Wrong Answer

Solution code:
import copy

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

b1 = copy.deepcopy(b)

cnt = 0
r = sorted(r, key=lambda a : a[0])
for i in range(N):
    x = r[i][0]
    y = r[i][1]
    flag = False
    for j in range(len(b)):
        mix = 100000
        if (b[j][0] > x and b[j][1] > y):
            flag = True
            if mix > b[j][0]:
                idx = j
                mix = b[j][0]
    if flag:
        cnt += 1
        del b[idx]
cnt2 = 0
r = sorted(r, key=lambda a : a[1])
for i in range(N):
    x = r[i][0]
    y = r[i][1]
    flag = False
    for j in range(len(b1)):
        miy = 100000
        if (b1[j][0] > x and b1[j][1] > y):
            flag = True
            if miy > b1[j][1]:
                idx = j
                miy = b1[j][1]
    if flag:
        cnt2 += 1
        del b1[idx]
print(max(cnt,cnt2))

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

if __name__ == '__main__':
    N = int(input().strip())
    lines = [input().split() for _ in range(N)]
    a_b = [(int(line[0]), int(line[1])) for line in lines]
    lines = [input().split() for _ in range(N)]
    c_d = [(int(line[0]), int(line[1])) for line in lines]

    # N = 5
    # a_b = [(0, 0), (1, 1), (5, 5), (6, 6), (7, 7)]
    # c_d = [(2, 2), (3, 3), (4, 4), (8, 8), (9, 9)]

    a_b = sorted(a_b, key=lambda e: max(e[0], e[1]))
    c_d = sorted(c_d, key=lambda e: max(e[0], e[1]))

    count = 0

    candidates = defaultdict(list)
    for i, (a, b) in enumerate(a_b):
        for j, (c, d) in enumerate(c_d):
            if a < c and b < d:
                candidates[(a, b)].append((c, d))
                # #
                # # count += 1
                # # c_d.remove((c, d))
                # break
        #         candidates[(c - a) + (d - b)] = (c, d)
        #
        # print(candidates)
        #
        # if candidates:
        #     sorted_keys = sorted(candidates.keys())
        #     selected = candidates[sorted_keys[0]]
        #     print("selected:", selected)
        #     c_d.remove(selected)
        #     count += 1

    while len(candidates) != 0:
        ordered = sorted(candidates.items(), key=lambda pair: len(pair[1]))
        c_d_selected = ordered[0][1][0]
        count += 1
        candidates.pop(ordered[0][0])
        for k in candidates.keys():
            if c_d_selected in candidates[k]:
                candidates[k].remove(c_d_selected)

        candidates = {k: v for k, v in candidates.items() if len(v) != 0}

    # print(candidates)
    print(count)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
n = int(input())
ired = []
iblue = []

for i in range(n):
    a,b = map(int,input().split())
    ired.append([a,b])
    
for i in range(n):
    c,d = map(int,input().split())
    iblue.append([c,d])

red = sorted(ired)
blue = sorted(iblue)

flag = False
if [0,0] in red:
    red.remove([0,0])
    flag = True
    
x_ans = 0

y_ans = 0        
for i in range(n):
    for j in range(len(red)):
        if (blue[i][0] > red[j][0]) and (blue[i][1] > red[j][1]):
            red[j] = [-1,-1]
            x_ans += 1
            break 
        
red = sorted(ired,key = lambda x:x[1])
blue = sorted(iblue,key = lambda x:x[1])


if [0,0] in red:
    red.remove([0,0])
    flag = True
    
y_ans = 0        
for i in range(n):
    for j in range(len(red)):
        if (blue[i][0] > red[j][0]) and (blue[i][1] > red[j][1]):
            red[j] = [-1,-1]
            y_ans += 1
            break        

 
if flag and len(iblue) > x_ans:
    x_ans += 1
    
if flag and len(iblue) > y_ans:
    y_ans += 1
   

print(max(x_ans,y_ans))

Submission status: Wrong Answer

Solution code:
N=int(input())
Red=[[0,0,0]]*N

for i in range(N):
	a,b=input().split()
	#Red[i] = [(int(a)+int(b)),int(a),int(b)]
	Red[i] = [int(a),int(b)]

Blue=[[0,0,0]]*N
for i in range(N):
	a,b=input().split()
	#Blue[i]=[(int(a)+int(b)),int(a),int(b)]
	Blue[i]=[int(a),int(b)]

Red.sort()
Blue.sort()

#print("R:{}".format(Red))
#print("B:{}".format(Blue))

ans=0
for i in range(N):
	for l in range(N):
		for k in range(N):
			if Blue[k][0] >= Red[i][0] + l and Blue[k][1] >= Red[i][1] + l:
				#if Red[i][0] < Blue[k][0] and Red[i][1] < Blue[k][1]:
					#print("R:{},B:{}".format(Red[i],Blue[k]))
					ans += 1
					Blue[k][0] = 0
					Red[i][0] = Blue[N-1][0]+1
					#print("R:{}".format(Red))
					#print("B:{}".format(Blue))
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

if __name__ == '__main__':
    # N = int(input().strip())
    # lines = [input().split() for _ in range(N)]
    # a_b = [(int(line[0]), int(line[1])) for line in lines]
    # lines = [input().split() for _ in range(N)]
    # c_d = [(int(line[0]), int(line[1])) for line in lines]

    N = 5
    a_b = [(0, 0), (1, 1), (5, 5), (6, 6), (7, 7)]
    c_d = [(2, 2), (3, 3), (4, 4), (8, 8), (9, 9)]

    a_b = sorted(a_b, key=lambda e: max(e[0], e[1]))
    c_d = sorted(c_d, key=lambda e: max(e[0], e[1]))

    count = 0

    candidates = defaultdict(list)
    for i, (a, b) in enumerate(a_b):
        for j, (c, d) in enumerate(c_d):
            if a < c and b < d:
                candidates[(a, b)].append((c, d))
                # #
                # # count += 1
                # # c_d.remove((c, d))
                # break
        #         candidates[(c - a) + (d - b)] = (c, d)
        #
        # print(candidates)
        #
        # if candidates:
        #     sorted_keys = sorted(candidates.keys())
        #     selected = candidates[sorted_keys[0]]
        #     print("selected:", selected)
        #     c_d.remove(selected)
        #     count += 1

    while len(candidates) != 0:
        ordered = sorted(candidates.items(), key=lambda pair: len(pair[1]))
        c_d_selected = ordered[0][1][0]
        count += 1
        candidates.pop(ordered[0][0])
        for k in candidates.keys():
            if c_d_selected in candidates[k]:
                candidates[k].remove(c_d_selected)

        candidates = {k: v for k, v in candidates.items() if len(v) != 0}

    # print(candidates)
    print(count)

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

cand = []
for b in B:
    temp = []
    for i, r in enumerate(R):
        if r[0] < b[0] and r[1] < b[1]:
            temp.append(i)
    cand.append(temp)

cand = sorted(cand, key=lambda x: len(x))

result = 0
d = [False for _ in range(N)]
while True:
    flag = False
    for c in cand:
        if len(c) == 1:
            flag = True
    cnt = d.count(True)

    if flag:
        for j, c in enumerate(cand):
            if 0 < len(c):
                num = c[0]
                if len(c) == 1 and not d[num]:
                    result += 1
                    d[num] = True
                    for i in cand:
                        if num in i:
                            i.remove(num)
                cand[j] = []
                break
    else:
        cnt = [0 for _ in range(N)]
        for c in cand:
            for i in range(N):
                cnt[i] += c.count(i)
        flag = False
        for i in range(N):
            if cnt[i] == 1:
                idx = i
                flag = True
                break

        if flag:
            num = idx
            result += 1
            d[num] = True
            for i, c in enumerate(cand):
                if num in c:
                    cand[i] = []
        else:
            cnt = d.count(True)
            for j, c in enumerate(cand):
                if 0 < len(c):
                    num = c[0]

                    result += 1
                    d[num] = True
                    for i in cand:
                        if num in i:
                            i.remove(num)
                    cand[j] = []
                    break

    if cnt == d.count(True):
        break

print(result)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[]
b=[]
for i in range(n):
    a.append(list(map(int,input().split())))
for i in range(n):
    b.append(list(map(int,input().split())))
an=sorted(a, key=lambda x:(x[0],-x[1]))
bn=sorted(b, key=lambda x:(x[0],-x[1]))
count=0
for i in range(len(bn)):
    for j in range(len(an)):
#        print(an[j],bn[i])
        if bn[i][0]>an[j][0] and bn[i][1]>an[j][1]:
            count+=1
            an.pop(j)
            break
 
print(count)

Submission status: Wrong Answer

Solution code:

n = int(input())
red = []
blue = []

for i in range(n):
    x, y = map(int, input().split())
    red.append((x, y))
for i in range(n):
    x, y = map(int, input().split())
    blue.append((x, y))

sr = list(reversed(sorted(red)))
sb = list(reversed(sorted(blue)))
sry = list(reversed(sorted(red, key=lambda tup: tup[1])))
sby = list(reversed(sorted(blue, key=lambda tup: tup[1])))
ans = 0
ans2 = 0
for i in range(n):
    sby = []
    for j in range(n):
        if(sr[i][0] < sb[j][0] and sr[i][1] < sb[j][1]):
            sby.append(sb[j])
    sby = list(reversed(sorted(sby, key=lambda tup: tup[1])))
    for j in range(len(sby)):
        if(sr[i][0] < sby[j][0] and sr[i][1] < sby[j][1]):
            ans += 1
            sb[sb.index(sby[j])] = (-1, -1)
            sr[i] = (2 * n + 1, 2 * n + 1)
            break
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
Red=[[0,0,0]]*N

for i in range(N):
	a,b=input().split()
	#Red[i] = [(int(a)+int(b)),int(a),int(b)]
	Red[i] = [int(a),int(b)]

Blue=[[0,0,0]]*N
for i in range(N):
	a,b=input().split()
	#Blue[i]=[(int(a)+int(b)),int(a),int(b)]
	Blue[i]=[int(a),int(b)]

Red.sort()
Blue.sort()

#print("R:{}".format(Red))
#print("B:{}".format(Blue))

ans=0
for i in range(N):
	for l in range(N):
		for k in range(N):
			if Blue[k][0] > Red[i][0] + l and Blue[k][1] > Red[i][1] + l:
				if Red[i][0] < Blue[k][0] and Red[i][1] < Blue[k][1]:
					#print("R:{},B:{}".format(Red[i],Blue[k]))
					ans += 1
					Blue[k][0] = 0
					Red[i][0] = Blue[N-1][0]+1
					#print("R:{}".format(Red))
					#print("B:{}".format(Blue))
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
import sys
import numpy as np

n = input()
red = []
blue = []
for i in range(n):
    a, b = map(int, raw_input().split())
    red.append((a, b))
for i in range(n):
    a, b = map(int, raw_input().split())
    blue.append((a, b))
m = np.zeros((n, n))
for i in range(n):
    for j in range(n):
        m[i, j] = int(red[i][0] < blue[j][0] and red[i][1] < blue[j][1])
print np.linalg.matrix_rank(m)

Submission status: Wrong Answer

Solution code:
N=int(input())
Red=[[0,0,0]]*N

for i in range(N):
	a,b=input().split()
	#Red[i] = [(int(a)+int(b)),int(a),int(b)]
	Red[i] = [int(a),int(b)]

Blue=[[0,0,0]]*N
for i in range(N):
	a,b=input().split()
	#Blue[i]=[(int(a)+int(b)),int(a),int(b)]
	Blue[i]=[int(a),int(b)]

Red.sort()
Blue.sort()

#print("R:{}".format(Red))
#print("B:{}".format(Blue))

ans=0
for i in range(N):
	for l in range(N):
		for k in range(N):
			if Blue[k][0] > Red[i][0] + l and Blue[k][1] > Red[i][1] + l:
				#if Red[i][0] < Blue[k][0] and Red[i][1] < Blue[k][1]:
					#print("R:{},B:{}".format(Red[i],Blue[k]))
					ans += 1
					Blue[k][0] = 0
					Red[i][0] = Blue[N-1][0]+1
					#print("R:{}".format(Red))
					#print("B:{}".format(Blue))
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(raw_input())

red = []
blue = []

for a in range(n):
  q = map(int,raw_input().split(" "))
  red.append(q)

for a in range(n):
  q = map(int,raw_input().split(" "))
  blue.append(q)

red.sort()
blue.sort()
G = []
for a in range(n):
  G.append([])

used = [0]*n
match = [-1]*n

def add_edge(u,v):
  global G
  G[u].append(v)

def dfs(v):
  global G,match,used
  used[v] = 1
  for i in range( len(G[v]) ):
    u = G[v][i]
    w = match[u]
    if w < 0 or (used[w] != 1) and dfs(w) == 1:
      match[v] = u
      match[u] = v
      return 1
  return 0

for a in range(n):
  for b in range(n):
    if red[a][0] < blue[b][0] and red[a][1] < blue[b][1]:
      add_edge(a,b)

ans = 0
for a in range(n):
  if match[a] < 0:
    used = [0]*n
    if dfs(a) == 1:
      ans += 1
print ans

Submission status: Wrong Answer

Solution code:
n = int(input())
a = []
b = []
c = []
d = []
count = 0
for i in range(n):
    a_ad, b_ad = map(int, input().split())
    a.append(a_ad)
    b.append(b_ad)
for i in range(n):
    c_ad, d_ad = map(int, input().split())
    c.append(c_ad)
    d.append(d_ad)
wa_red = [a[i]*a[i] + b[i]*b[i] for i in range(n)]
wa_blue = [c[i]*c[i] + d[i]*d[i] for i in range(n)]
wa_red_sort = sorted(wa_red, reverse = True)
wa_blue_sort = sorted(wa_blue)
for i in range(n):
    ind_a = wa_red.index(wa_red_sort[i])
    l = len(c)
    for k in range(l):
        ind_c = wa_blue.index(wa_blue_sort[k])
        if a[ind_a] < c[ind_c] and b[ind_a] < d[ind_c]:
            c = c[:ind_c] + c[ind_c+1:]
            d = d[:ind_c] + d[ind_c+1:]
            wa_blue_sort = wa_blue_sort[:k] + wa_blue_sort[k+1:]
            wa_blue = wa_blue[:ind_c] + wa_blue[ind_c+1:]
            count += 1
            break
print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
ired = []
iblue = []

for i in range(n):
    a,b = map(int,input().split())
    ired.append([a,b])
    
for i in range(n):
    c,d = map(int,input().split())
    iblue.append([c,d])

red = sorted(ired)
blue = sorted(iblue)


    
x_ans = 0

for i in range(len(red)):
    for j in range(n):
        if (blue[i][0] > red[j][0]) and (blue[i][1] > red[j][1]):
            red[j] = [300,300]
            x_ans += 1
            break
        
red = sorted(ired,key = lambda x:x[1])
blue = sorted(iblue,key = lambda x:x[1])


    
y_ans = 0        
for i in range(len(red)):
    for j in range(n):
        if (blue[i][0] > red[j][0]) and (blue[i][1] > red[j][1]):
            red[j] = [300,300]
            y_ans += 1
            break        

 

   

print(max(x_ans,y_ans))

Submission status: Wrong Answer

Solution code:
N = int(input())
pairs = 0

a = [list(map(int,input().split())) for i in range(N)]
b = [list(map(int,input().split())) for i in range(N)]
btree = [{} for i in range(N)]


def small(a,b):
    return (a[0] < b[0] and a[1] < b[1])

for i in range(len(b)):
    for a_point in a:
        if small(a_point,b[i]):
            btree[i][str(a_point[0])+" "+str(a_point[1])] = 1
length = 0
min_len = 1
for bt in btree:
    length += len(bt)
k = 0
f_length = length
while length > 0:
    key = 0
    kouho = []
    hozon = []
    for i in range(N):
        if len(btree[i]) == min_len:
            key += 1
            kouho.append(btree[i].keys())
            hozon.append(i)
            min_have = 10000000
            kei = 0
            basyo = 0
            for j in range(len(kouho)):
                for keys in kouho[j]:
                    sub = 0
                    for i in range(N):
                        if keys in btree[i]:
                           sub += 1
                    if sub < min_have:
                        kei = keys
                        basyo = j
            length -= (len(btree[basyo]))
            pairs += 1
            btree[basyo] = {}
            for i in range(N):
                if str(kei) in btree[i]:
                    del btree[i][str(kei)]
                    length -= 1
            min_len = 1
            break
    if key <= 0:
        min_len += 1
if f_length ==0:
    print(0)
else:
    print(pairs)