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: Runtime Error

Solution code:
#pragma GCC optimize("unroll-loops")
/**
 *      purpose : 
 *      author  : kyomukyomupurin
 *      created : 
**/

// input/output
#include <fstream>
#include <iostream>
#include <sstream>
// container class
#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// math, algorithm
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// etc
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstring>
#include <chrono>
#include <ext/random>
#include <ext/rope>
#include <functional>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias template
using int64 = long long;
using ull = unsigned long long;
using vi = std::vector<int>;
using vl = std::vector<int64>;
using pii = std::pair<int, int>;
using pii = std::pair<int, int>;
using pll = std::pair<int64, int64>;
// text macro replacement
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(_) (_).begin(), (_).end()
#define rall(_) (_).rbegin(), (_).rend()
#define print(_) std::cout << (_) << '\n'
#define debug(_) std::cerr << #_ << ": " << (_) << '\n'
// variadic template
template<typename T> inline void chmin(T &a, T b) {if (a > b) a = b; return;}
template<typename T> inline void chmax(T &a, T b) {if (a < b) a = b; return;}
template<typename T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) {
  os << '{';
  for (size_t i = 0; i < vec.size(); ++i) {
    os << vec[i];
    if (i != vec.size() - 1) os << ',';
  }
  os << '}';
  return os;
}
template<typename T, typename U> std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) {
  return os << '{' << p.first << " " << p.second << '}';
}
// constant
const int INF = (1<<30) - 1;  // 1.073741823e9
const int64 INF64 = (1LL<<62) - 1;  // 4.611686018427387903e18
const int MOD = 1000000007;

struct Red {
  int x, y;
};

struct Blue {
  int x, y;
};

int main(){
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);

  int n; cin >> n;
  vector<Red> r;
  vector<Blue> b;
  rep(i, n) {
    int a, b; cin >> a >> b;
    r.push_back({a, b});
  }
  rep(i, n) {
    int c, d; cin >> c >> d;
    b.push_back({c, d});
  }

  sort(b.begin(), b.end(), [](const Blue& p, const Blue& q) {
    return p.x < q.x;
  });

  sort(r.begin(), r.end(), [](const Red& p, const Red& q) {
    return p.y > q.y;
  });

  bool used[n] = {};

  int ans = 0;

  rep(i, n) {
    rep(j, n) {
      if (used[j]) continue;
      if (r[j].x < b[i].x && r[j].y < b[i].y) {
        ++ans;
        used[j] = true;
        break;
      }
    }
  }

  cout << ans << '\n';

  return 0;
}

Submission status: Runtime Error

Solution code:
n = int(input())
aka = []
ao = []
for _ in range(n):
    ab = sorted(list(map(int, input().split())), key=lambda x:x[1], reverse=True)
    aka.append(ab)
for _ in range(n):
    cd = sorted(list(map(int, input().split())))
    ao.append(cd)
count = 0
for a, b in aka:
    for c, d in ao:
        if a<c and b<d:
            ao.remove(c,d)
            count+=1
            break
print(count)

Submission status: Runtime Error

Solution code:
n = int(input())
aka = []
ao = []
for _ in range(n):
    ab = sorted(list(map(int, input().split())), key=lambda x:x[1], reverse=True)
    aka.append(ab)
for _ in range(n):
    cd = sorted(list(map(int, input().split())))
    ao.append(cd)
count = 0
for a, b in aka:
    for c, d in ao:
        if a<c and b<d:
            ao.remove(c,d)
            count+=1
print(count)

Submission status: Runtime Error

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

    d = dict()
    for i in range(N):
        for j in range(N):
            if blue[i][0] > red[j][0] and blue[i][1] > red[j][1]:
                if i not in d:
                    d[i] = [j]
                else:
                    d[i].append(j)
    lv = sorted(d.values(), key = lambda x: len(x))
    used = set()
    while lv:
        v = lv[0][0]
        used.add(v)
        temp = []
        for ls in lv[1:]:
            if v in ls:
                ls.remove(v)
            if len(ls) > 0:
                temp.append(ls)
        lv = temp
        lv = sorted(d.values(), key = lambda x: len(x))
    return len(used)

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

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
from scipy.optimize import linear_sum_assignment
import numpy as np

N = int(input())
AB = [[int(x) for x in input().split()] for _ in range(N)]
CD = [[int(x) for x in input().split()] for _ in range(N)]

mat = np.zeros((N,N),dtype=np.int32)

for i,(a,b) in enumerate(AB):
    for j,(c,d) in enumerate(CD):
        if a<c and b<d:
            mat[i,j] -= 1


I,J = linear_sum_assignment(mat)

answer = -mat[I,J].sum()
print(answer)

Submission status: Runtime Error

Solution code:
#include <iostream>
#include <utility>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;

int main(){
  int N;
  cin >> N;
  vector<pair<int,int>> red;
  for(int i = 0;i < N;i++){
    int a,b;
    cin >> a >> b;
    red.push_back(make_pair(a,b));
  }

  vector<pair<int,int>> blue;
  for(int i = 0;i < N;i++){
    int c,d;
    cin >> c >> d;
    blue.push_back(make_pair(c,d));
  }

  sort(red.begin(),red.end(),greater<pair<int,int>>());
  sort(blue.begin(),blue.end());

  int ans = 0;
  for(int i = 0;i < N;i++){
    auto itr = upper_bound(blue.begin(),blue.end(),red[i]);
    int select_range = blue.end() - itr;
    if(ans < select_range){
      ans++;
    }
  }


  cout << ans << endl;

}

Submission status: Runtime Error

Solution code:
n = int(input())  
red_li = [list(map(int, input().split())) for _ in range(n)]
blue_li = [list(map(int, input().split())) for _ in range(n)]
ans = 0
red_li.sort(reverse = True, key = lambda x : (x[0], x[1]))
blue_li.sort( key = lambda x : (x[0], x[1]))

def count(red, blue, used_red, used_blue):
    used_red = []
    used_blue = []
    for i in red:
        if i in used_red:
            continue
        for j in blue:
            if j in used_blue:
                continue
            if i[0] < j[0] and i[1] < j[1]:
                used_red.append(i)
                used_blue.append(j)
                break
    return len(used_red)

ans = count(red_li, blue_li)
red_li.sort(reverse = True,key = lambda x : (x[1], x[0]))
blue_li.sort( key = lambda x : (x[1], x[0]))
ans = max(ans, count(red_li, blue_li))
red_li.sort(reverse = True,key = lambda x : (x[1], x[0]))
blue_li.sort( key = lambda x : (x[0], x[1]))
ans = max(ans, count(red_li, blue_li))
red_li.sort(reverse = True,key = lambda x : (x[0], x[1]))
blue_li.sort( key = lambda x : (x[1], x[0]))
ans = max(ans, count(red_li, blue_li))
print(ans)

Submission status: Runtime Error

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)]
v=[]
r.sort()
b.sort()
print(r)
print(b)
count=0

for i in range(n):
    for j in range(n):
        if b[i][0]<=r[j][0] or b[i][1]<=r[j][1]:
            break
        else:
            v.append(r[j])    
    if v!=[]:
        v.sort(key=lambda x:x[1])
        print(v)
        r.remove(v[0])
        
            
        v=[]
        count+=1
print(count)

Submission status: Runtime Error

Solution code:
import numpy as np

n = int(input())
r = []
b = []

for i in range(n):
    x,y = map(int,input().split())
    r.append([x,y])

for i in range(n):
    x,y = map(int,input().split())
    b.append([x,y])



r.sort(key=lambda x:[x[0],-x[1]])
b.sort(key=lambda x:[x[0],-x[1]])

r2 = r.copy()
b2 = b.copy()

r2.sort(key=lambda x:[x[1],-x[0]])
b2.sort(key=lambda x:[x[1],-x[0]])
# print(r)
# print(b)

ans = 0
for i in range(n):
    x,y = b[i][0],b[i][1]
    # print(x,y)
    tar = 0
    flag = False
    for j in range(len(r)):
        if r[j][0] < x and r[j][1] < y:
            flag = True
            tar = j
    if flag:
        ans += 1
        r.pop(tar)


ans2 = 0

for i in range(n):
    x,y = b2[i][0],b2[i][1]
    # print(x,y)
    tar = 0
    flag = False
    for j in range(len(r)):
        if r2[j][0] < x and r2[j][1] < y:
            flag = True
            tar = j
    if flag:
        ans2 += 1
        r2.pop(tar)

print(max(ans,ans2))

Submission status: Runtime Error

Solution code:
import numpy as np

n = int(input())
r = []
b = []

for i in range(n):
    x,y = map(int,input().split())
    r.append([x,y])

for i in range(n):
    x,y = map(int,input().split())
    b.append([x,y])



r.sort(key=lambda x:[x[0],x[1]])
b.sort(key=lambda x:[x[0],x[1]])

r2 = r.copy()
b2 = b.copy()

r2.sort(key=lambda x:[x[1],x[0]])
b2.sort(key=lambda x:[x[1],x[0]])
# print(r)
# print(b)

ans = 0
for i in range(n):
    x,y = b[i][0],b[i][1]
    # print(x,y)
    tar = 0
    flag = False
    for j in range(len(r)):
        if r[j][0] < x and r[j][1] < y:
            flag = True
            tar = j
    if flag:
        ans += 1
        r.pop(tar)


ans2 = 0

for i in range(n):
    x,y = b2[i][0],b2[i][1]
    # print(x,y)
    tar = 0
    flag = False
    for j in range(len(r)):
        if r2[j][0] < x and r2[j][1] < y:
            flag = True
            tar = j
    if flag:
        ans2 += 1
        r2.pop(tar)

print(max(ans,ans2))

Submission status: Runtime Error

Solution code:
N = int(input())

reds = []
for _ in range(N):
    reds.append(tuple(map(int, input().split())))
    
blues = []
for _ in range(N):
    blues.append(tuple(map(int, input().split())))

reds.sort()
blues.sort()

ans = 0
for blue in blues:
    c, d = blue

    # 条件に当てはまる赤を抽出
    targets = [red for red in reds if red[0] < c and red[1] < d]
    targets.sort(key=lambda x:x[1])

    # 赤のうち一番y座標が大きいものを抽出
    if reds_under_x:
        target = reds_under_x.pop()
        reds.remove(target)
        ans += 1

print(ans)

Submission status: Runtime Error

Solution code:
import sys

sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(N, inputs):
    ball_str = list(map(lambda i: string_to_int(i), inputs))
    balls = list(map(lambda b: [b[0], b[1], -1], ball_str))

    red = balls[:N]
    blue = balls[N:]

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

    count = 0
    for i, r in enumerate(red):
        for j, b in enumerate(blue):
            if r[0] < b[0] and r[1] < b[1] and b[2] == -1:
                count += 1
                r[2] = j
                b[2] = i
                break
    return count


def string_to_int(string):
    return list(map(lambda x: int(x), string.split()))


if __name__ == "__main__":
    [N] = string_to_int(inputs())
    ret = solve(N, inputs(N))
    print(ret)

Submission status: Runtime Error

Solution code:
n = int(input())
red = []
blue = []
for _ in range(n):
    a, b = map(int, input().split())
    red.append([a, b])
for _ in range(n):
    c, d = map(int, input().split())
    blue.append([c, d])
red.sort()
b.sort()
count = 0
for i in range(n):
    a, b = red.pop(0)
    for j in range(len(blue)):
        if (a < blue[j][0]) & (b < blue[j][1]):
            count += 1
            blue.pop(j)
            break

Submission status: Runtime Error

Solution code:
N = int(input())
R = sorted([list(map(int,input()split())) for i in range(N)], key=lambda x: x[0],reverse=False)
B = sorted([list(map(int,input()split())) for i in range(N)], key=lambda x: x[1],reverse=True)

ans = 0

start = 0

for a,b in R :
    for i in range(start,N) :
        c,d = B[i]
        if (c-a > 0) and (d-b > 0) :
            start = i+1
            ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
r=[]
for i in range(n):
    a,b=map(int,input().split())
    r.append((a,b))
l=[]
for i in range(n):
    c,d=map(int,input().split())
    l.append((c,d))


r.sort()
l.sort(key=lambda x:x[1],reverse=1)
ans=0
for s,t in r.copy():
    for p,q in l.copy():
        if s<p and t<q:
            ans+=1
            r.remove((s,t))
            l.remove((p,q))
print(ans)

Submission status: Runtime Error

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)]
red.sort()
blue.sort()
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]:
            a = j
    if blue[i][0] > red[a][0] and blue[i][1] > red[a][1]:
        ans += 1
        del red[a]
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
x = sorted([list(map(int, input().split())) for _ in range(N)], reverse=True)
y = sorted([list(map(int, input().split())) for _ in range(N)], reverse=True)

i = 0
j = 0
cnt = 0
while j < N:
    if x[i][0] < y[j][0] and x[i][1] < y[j][1]:
        cnt += 1
        i += 1
        j += 1
        continue
    else:
	    i += 1
    if i >= N:
      i = 0
      j += 1
print(cnt)

Submission status: Runtime Error

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

ans = 1
for blue in Blue:
    for red in Red:
        if red[0] < b[0] and red[1] < b[1]:
            ans += 1
            Red.remove(red)
            break

print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
AB = [[0]+list(map(int,input().split())) for _ in range(n)]
CD = [list(map(int,input().split())) for _ in range(n)]
from operator import itemgetter
points = AB.copy()
for c,d in CD:
    points.append([1,c+0.1,d+0.1])
points.sort(key = itemgetter(1))
points.sort(key = itemgetter(2))

ans = 0
record = [0]*(2*n+1)
for flag, x, y in points:
    if flag:
        ans += sum(record[x:y])
    else:
        record[x] += 1
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
AB = [[0]+list(map(int,input().split())) for _ in range(n)]
CD = [[1]+list(map(int,input().split())) for _ in range(n)]
from operator import itemgetter
points = AB.copy()
for c,d in CD:
    points.append([c+0.1,d+0.1])
points.sort(key = itemgetter(2))
points.sort(key = itemgetter(1))
temp = 0
ans = 0
for flag, x, y in points:
    if flag:
        if temp > 0:
            ans += 1
            temp -= 1
    else:
        temp += 1
print(ans)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
import sys
INF = float("inf")
import matplotlib.pyplot as plt


def solve(N: int, a: "List[int]", b: "List[int]", c: "List[int]", d: "List[int]"):
    red = [[a[i], b[i], False] for i in range(N)]
    blue = [[c[i], d[i], False] for i in range(N)]

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

    # print(red)
    # print(blue)
    ans = 0

    for b in blue:
        cand = [i for i, r in enumerate(red) if r[0] < b[0] and r[1] < b[1]]
        # fix
        if len(cand) > 0:
            ans += 1
            i = max(cand, key=lambda i: red[i][1])
            red.pop(i)
    print(ans)

    # flag = True
    # while flag:
    #     flag = False
    #     for i in range(N):
    #         if red[i][2] == True:
    #             continue
    #         cand = []
    #         counter = 0
    #         for j in range(N):
    #             if blue[j][2] == True:
    #                 continue
    #             if red[i][0] < blue[j][0] and red[i][1] < blue[j][1]:
    #                 counter += 1
    #                 cand.append(j)
    #         if counter == 1:
    #             red[i][2] = True
    #             blue[cand[0]][2] = True
    #             flag = True
    #             ans += 1
    #             print("pair ", red[cand[0]], blue[cand[0]])
    # print(ans)
    # for i in range(N):
    #     if red[i][2]:
    #         plt.scatter(red[i][0], red[i][1], color="red", marker="o")
    #     else:
    #         plt.scatter(red[i][0], red[i][1], color="orange", marker="o")
    # for i in range(N):
    #     if blue[i][2]:
    #         plt.scatter(blue[i][0], blue[i][1], color="blue", marker="o")
    #     else:
    #         plt.scatter(blue[i][0], blue[i][1], color="navy", marker="o")
    # plt.show()
    # return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [int()] * (N)  # type: "List[int]"
    b = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        a[i] = int(next(tokens))
        b[i] = int(next(tokens))
    c = [int()] * (N)  # type: "List[int]"
    d = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        c[i] = int(next(tokens))
        d[i] = int(next(tokens))
    solve(N, a, b, c, d)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

def abX():
    ans = 0
    for a,b in AB:
        for c,d in CD:
            if a<c and b<d:
                ans+=1
                CD.remove([c,d])
                break
    return ans

def abY():
    ans = 0
    for a,b in ab:
        for c,d in cd:
            if a<c and b<d:
                ans+=1
                cd.remove([c,d])
                break
    return ans

print(max(abX(),abY()))

Submission status: Runtime Error

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

red_max = []
blue_min = []
for i in range(n):
    red_max.append(max(a[i]))
    blue_min.append(min(a[i + n]))

red_max.sort()
blue_min.sort()

import numpy as np
red_max = np.array(red_max)
blue_min = np.array(blue_min)

i = 0
while True:
    j = np.where(blue_min >= red_max[i])[0][0]

    if j == n:
        break
    else:
        blue_min = blue_min[j+1:]
        i += 1
print(i-1)

Submission status: Runtime Error

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 = [Flase 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: Runtime Error

Solution code:
#ABC091C
N=int(input())
A=[]
B=[]
for n in range(N):
	A.append(list(map(int,input().split())))
for n in range(N):
	B.append(list(map(int,input().split())))
A.sort(key=lambda x:(x[0],x[1]))
B.sort(key=lambda x:(x[0],x[1]))
def DP(ca,cb):
	global A,B,N
	c=0
	d=0
	for b in range(ca.index(1),N):
		for a in range(cb.index(1),N):
			if A[a][0]>B[b][0]:
				break
			else:
				if ca[a] and cb[b]:
					if A[a][1]<B[b][1]:
						d=1
						c=max(c,DP(ca[:a]+[0]+ca[a+1:],\
							cb[:b]+[0]+cb[b+1:]))
	return c+d
ca=[1 for _ in range(N)]
cb=[1 for _ in range(N)]
print(DP(ca,cb))

Submission status: Runtime Error

Solution code:
 
n = int(input())
red = [[0,0]]*n
for i in range( n ):
    red[i] = map(int, input().split())
    red.sort(key = lambda p:p[0])
    red.sort(key = lambda p:p[1], reverse = True) 
    
blue = [ ( map(int,input().split()) ) for i in range( n )]
blue.sort(key = lambda p:p[0])
    
paired = [False] * len(blue)
ans = 0
    
for i in range(n):
    for j in range(n):
            
        if paired[j]:
            continue
            
        if red[i][0] < blue[j][0] and \
            red[i][1] < blue[j][1] :# and \
                #paired[j] is False:
    #        print('{}, {}'.format(red[i],blue[j]))
            paired[j] = True
            ans += 1
            break
                
print(ans)

Submission status: Runtime Error

Solution code:


n = int(input())
rx,ry = [],[]
for i in range(n):
  rx[i], ry[i] = map(int,input().split())
  
bx, by = [],[]
for i in range(n):
  bx[i], by[i] = map(int, input().split())

red = [[0,0]]*len(rx)
for i in range( len(rx) ):
    red[i] = rx[i], ry[i]
    red.sort()
    red.sort(key = lambda p:p[1], reverse = True) 
    
blue = [ (bx[i],by[i]) for i in range( len(bx) )]
blue.sort()
    
paired = [False] * len(blue)
ans = 0
    
for i in range(len(rx)):
    for j in range(len(bx)):
            
        if paired[j]:
            continue
            
        if red[i][0] < blue[j][0] and \
            red[i][1] < blue[j][1] :# and \
                #paired[j] is False:
    #        print('{}, {}'.format(red[i],blue[j]))
            paired[j] = True
            ans += 1
            break
                
print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
mp=[[] for i in range(n)]
MP=[[] for i in range(n)]
for i in range(n):
  mp[i]=list(map(int,input().split()))
for j in range(n):
  MP[j]=list(map(int,input().split()))
counT=[]
for k in mp:
  ans=0
  for k in MP:
    if k[0]<K[0] and k[1]<K[1]:
      ans+=1
  counT.append(ans)
qwe=0
for i in range(n):
  if counT[i]!=0:
    qwe+=1
print(min(max(counT),qwe))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n = int(input())
r = []
b = []
c = 0
for i in range(n):
  r.append(list(map(int,input().split())))
for i in range(n):
  b.append(list(map(int,input().split())))
r.sort(key = itemgetter(1),reverse = True)
b.sort(key = itemgetter(0))
for i in range(n):
  for j in range(n):
    if b[i][0] > r[j][0] and b[i][1] > r[j][1]:
      r[j] = [10**6,10**6]
      c += 1
      break
print(c)

Submission status: Runtime Error

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)]
R.sort(key = lambda x:x[1], reverse = True)
B.sort()
ans = 0
check = []


for bx, by in B:
    for i in range(N):
        if bx > R[i][0] and by > R[i][1] and i not in check :
            ans += 1
            check.append(i)
            break
            #print('B', bx, by, 'R',R[i][0], R[i][1] )
print(ans)

Submission status: Runtime Error

Solution code:
  1 #!/usr/bin/env python3
  2 # -*- coding: UTF-8 -*-
  3 n=int(input())
  4 l,r=[],[]
  5 for i in range(n):
  6     x,y=map(int,input().split())
  7     l.append((x,y))
  8 l.sort()
  9 for i in range(n):
 10     x,y=map(int,input().split())
 11     r.append((x,y))
 12 r.sort()
 13 ans=[0]*n
 14 t=-1
 15 for i,j in l:
 16     t+=1
 17     for x,y in r:
 18         if i<x and j<y:
 19             ans[t]+=1
 20         else:
 21             break
 22 chk=0
 23 for i in ans:
 24     if i-chk>0: chk+=1
 25 print(chk)

Submission status: Runtime Error

Solution code:
z

Submission status: Runtime Error

Solution code:
    num=int(input())
    a_array=[]
    b_array=[]
    for n in range(2*num):
        elem=[int(n) for n in input().split()]
        if n < num:
            a_array.append(elem)
        else:
            b_array.append(elem)
    a_array.sort(key=lambda x:x[1])
    a_array.reverse()
    b_array.sort(key=lambda x: x[0])
    answer=0
    for b_x, b_y in b_array:
        for a_x, a_y in a_array:
            if b_x > a_x and b_y > a_y:
                answer=answer+1
                a_array.remove([a_x,a_y])
    print(answer)

Submission status: Runtime Error

Solution code:
pair_count = 0
for cd_i in cd:
	can_ball_count = 0
	for ab_i in ab:
		if ab_i[0] < cd_i[0] and ab_i[1] < cd_i[1]:
			can_ball_count += 1
		else:
			break
	if 1 <= can_ball_count-pair_count:
		pair_count += 1

print(pair_count)

Submission status: Runtime Error

Solution code:
N=int(input())
l=[list(map(int,input().split())) for _ in range(N)]
m=[list(map(int,input().split())) for _ in range(N)]
o=[[i for (i,j) in enumerate(m) if j[0]>k[0] and j[1]>k[1]] for k in l]
s=set()
for i in p:
  for l in i:
    if not l in s:
      s.add(l)
      break
print(len(s))

Submission status: Runtime Error

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], x[0]), reverse=True)
    B.sort(key=lambda x: (x[0], x[1]))
    f = [0] * N
    print(R)
    print(B)

    pair = 0
    for b in B:
        for i, r in enumerate(R):
            if r[0] < b[0] and r[1] < b[1] and f[i] == 0:
                print(r[0],r[1],b[0],b[1])
                pair += 1
                f[i] = 1
                break

    print(pair)

Submission status: Runtime Error

Solution code:
N = int(input())
red_point=[]
blue_point=[]
for i in range(N):
    red_point.append(list(map(int,input().split())))
for i in range(N):
    blue_point.append(list(map(int,input().split())))
red_point.sort(reverse=True)
blue_point.sort()
# print(blue_point)
ans = 0
temp = 0 
# print(red_point)
for i in range(N):
    redx,redy=red_point[i][0],red_point[i][1]
    for j in range(len(blue_point)):
        # print("({},{})".format(i,j))
        # print(blue_point)
        bluex,bluey=blue_point[j][0],blue_point[j][1]
        if redx<bluex and redy<bluey:
            if temp<redx:
                temp = redx
                tempj=j   
            ans +=1
            # red_point.pop(i)
            blue_point.pop(tempj)
            # break
print(ans)

Submission status: Runtime Error

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_sort = list(reversed(sorted(red, key=lambda y: y[1])))
blue_sort = sorted(blue, key=lambda x: x[0])

# print(red_sort)
# [[1, 3], [2, 0], [3, 1]]
# print(blue_sort)
# [[4, 2], [0, 4], [5, 5]]

pair = []
for blue_point in blue_sort:
    x_blue = blue_point[0]
    y_blue = blue_point[1]
    
    for red_point in red_sort:
        x_red = red_point[0]
        y_red = red_point[1]
        
        if x_red<x_blue and y_red<y_blue:
            if not (red point in pair) and not (red point in pair):
                pair.append(red_point)
                pair.append(blue_point)
    
print(len(pair) // 2)

Submission status: Runtime Error

Solution code:
pairs = []

for i in range(len(red)): #red[i]とペアになりうるものを探す
    if_break = 'false'    
#     if len(pairs) > 0:
#         print(pairs)
#     else:
#         print('not pairs')
        
    for j in range(i,len(blue)):
#         print(i,j)
#         print(red[i],blue[j])
        
        if if_break =='true':
            break
            
        if (red[i][0] < blue[i][0]) & (red[j][1] < blue[j][1]):
            pairs.append([red[i], blue[j]])
            if_break = 'true'
            break

    if if_break == 'true':
        continue
        
# print(pairs)
print(len(pairs))

Submission status: Runtime Error

Solution code:
n = int(input())
red = []
red_x = []
blue = []
blue_y = []
for i in range(n):
    a, b = map(int,input().split())
    red.append([a,b])
    red_x.append(a)
    
for i in range(n):
    c, d = map(int,input().split())
    blue.append([c,d])
    blue_y.append(d)

count = 0    
for i in range(n):
    p = max(red_x)
    s = min(blue_y)
    q = 0
    r = 0
    jjj = 0
    kkk = 0
    for j in range(len(red)):
        if red[j][0] == p:
            q = red[j][1]
            jjj = j
    for k in range(len(blue)):
        if blue[k][1] == s:
            r = blue[k][0]
            kkk = k
            
    if p < r and q < s:
        count = count + 1 
        red_x.remove(p)
        blue_y.remove(s)
        red.remove(red[jjj][0])
        blue.remove(blue[kkk][1])


    else:
        None
        
print(count)

Submission status: Runtime Error

Solution code:
n = int(input())
red = []
red_x = []
blue = []
blue_y = []
for i in range(n):
    a, b = map(int,input().split())
    red.append([a,b])
    red_x.append(a)
    
for i in range(n):
    c, d = map(int,input().split())
    blue.append([c,d])
    blue_y.append(d)

count = 0    
for i in range(n):
    p = max(red_x)
    s = min(blue_y)
    q = 0
    r = 0
    jjj = 0
    kkk = 0
    for j in range(n):
        if red[j][0] == p:
            q = red[j][1]
            jjj = j
    for k in range(n):
        if blue[k][1] == s:
            r = blue[k][0]
            kkk = k
            
    if p < r and q < s:
        count = count + 1 
        red_x.remove(p)
        blue_y.remove(s)
        red.remove(red[jjj][0])
        blue.remove(blue[kkk][1])


    else:
        None
        
print(count)

Submission status: Runtime Error

Solution code:
n = int(input())
red = []
red_x = []
blue = []
blue_y = []
for i in range(n):
    a, b = map(int,input().split())
    red.append([a,b])
    red_x.append(a)
    
for i in range(n):
    c, d = map(int,input().split())
    blue.append([c,d])
    blue_y.append(d)

count = 0    
for i in range(n):
    p = max(red_x)
    s = min(blue_y)
    q = 0
    r = 0
    jjj = 0
    kkk = 0
    for j in range(n):
        if red[j][0] == p:
            q = red[j][1]
            jjj = j
    for k in range(n):
        if blue[k][1] == s:
            r = blue[k][0]
            kkk = k
            
    if p < r and q < s:
        count = count + 1 
        red_x.remove(p)
        blue_y.remove(s)
        red.remove(red[jjj])
        blue.remove(blue[kkk])


    else:
        None
        
print(count)