Problem:
展覧会(Exhibition)
あなたは，絵の展覧会を開催しようとしている．展覧会では，いくつかの絵を額縁に入れ，左から右に一列に並べて展示する．
展覧会で展示する候補となる絵が$N$ 枚あり，1 から$N$ までの番号が付けられている．絵$i$ ($1 \leq i \leq N$) の大きさは$S_i$，価値は$V_i$ である．
また，これらの絵を入れるための額縁が$M$ 枚あり，1 から$M$ までの番号が付けられている．額縁$j$ ($1 \leq j \leq M$) の大きさは$C_j$ である．額縁$j$ には，大きさが$C_j$ 以下の絵のみを入れることができる．1 枚の額縁には高々1 枚の絵しか入れることができない．
展示する絵はすべて何らかの額縁に入っていなければならない．見栄えを良くするため，展示する絵は以下の条件を満たさなければならない：
左右に隣り合うどの2 枚の絵についても，右側の絵が入っている額縁の大きさは左側の絵が入っている額縁の大きさ以上である．
左右に隣り合うどの2 枚の絵についても，右側の絵の価値は左側の絵の価値以上である．
あなたは，できるだけ多くの絵を展示したい．
展示候補の絵の枚数，額縁の枚数，及びそれらの大きさや価値が与えられたとき，展示する絵の枚数の最大値を求めるプログラムを作成せよ．
入力
入力は以下の形式で標準入力から与えられる．
$N$ $M$
$S_1$ $V_1$
:
$S_N$ $V_N$
$C_1$
:
$C_M$
出力
標準出力に，展覧会に展示する絵の枚数の最大値を1 行で出力せよ．
制約
$ 1 \leq N \leq 100 000$.
$ 1 \leq M \leq 100 000$.
$ 1 \leq S i \leq 1 000 000 000 (1 \leq i \leq N)$.
$ 1 \leq V_i \leq 1 000 000 000 (1 \leq i \leq N)$.
$ 1 \leq C_j \leq 1 000 000 000 (1 \leq j \leq M)$.
入出力例
入力例1
3 4
10 20
5 1
3 5
4
6
10
4
出力例1
2
この入出力例では，左から順に(絵2, 額縁2)，(絵1, 額縁3) と並べることで，2 枚の絵を展示することができる．3 枚以上の絵を展示することはできないので，2 を出力する．ここで，(絵$i$, 額縁$j$) は，額縁$j$に入った絵$i$ を表す．
入力例2
3 2
1 2
1 2
1 2
1
1
出力例2
2
入力例3
4 2
28 1
8 8
6 10
16 9
4
3
出力例3
0
入力例4
8 8
508917604 35617051
501958939 840246141
485338402 32896484
957730250 357542366
904165504 137209882
684085683 775621730
552953629 20004459
125090903 607302990
433255278
979756183
28423637
856448848
276518245
314201319
666094038
149542543
出力例4
3
情報オリンピック日本委員会作 『第18 回日本情報オリンピック(JOI 2018/2019) 本選』

Submitted solutions:

code_snippet: #include<bits/stdc++.h>
using namespace std;

using lint = long long;

struct painting{
    lint s, v;

    bool operator<(const painting &rhs) const {
        return v == rhs.v ? s < rhs.s : v < rhs.v;
    }
};

int main(){
    int n, m;
    cin >> n >> m;

    vector<painting> p(n);
    for(int i = 0 ; i < n ; ++i){
        cin >> p[i].s >> p[i].v;
    }
    sort(p.rbegin(), p.rend());

    vector<lint> c(m);
    for(int i = 0 ; i < m ; ++i){
        cin >> c[i];
    }
    sort(c.rbegin(), c.rend());

    int ans = 0;
    for(int i = 0 ; i < n && ans < m ; ++i){
        if(p[i].s <= c[ans]){
            ++ans;
        }
    }

    cout << ans << endl;

    return 0;
}
accuracy: 1
time_ms: 80
memory_kb: 5492
final_rank: 17

code_snippet: #include <bits/stdc++.h>


using namespace std;
//make -f ../makefile SRC=
/*
*/


//------------------------------------------------------------------------------
bool DEBUG = false;
const int INF = 2147483647;

const int MAX_M = 100000;
static int frame[MAX_M];

typedef pair<int,int> PA;
typedef vector<PA> PAS;

//------------------------------------------------------------------------------
void debug_PAS(const PAS& PP)
{
    for (PA p: PP) printf("v=%d, s=%d\n", p.first, p.second);
}

bool compare(const PA& p1, const PA& p2)
{
    if (p1.first == p2.first) return p1.second > p2.second;
    return p1.first > p2.first;
}

int greedy(int N, PAS& PP, int M)
{
    //--------------------------------------------------------------------------
    // base cases:
    //--------------------------------------------------------------------------
    // init:
    sort(PP.begin(), PP.end(), &compare);
    if (DEBUG) debug_PAS(PP);
    sort(frame, frame+M, greater<int>());
    if (DEBUG) {printf("frame: "); for (int m=0; m<M; ++m) printf("%d ",frame[m]); printf("\n");}
    //--------------------------------------------------------------------------
    // compute:
    int res = 0;
    int m = 0;
    for (int i=0; i<N; ++i)
    {
        if (m < M && PP[i].second <= frame[m])
        {
            res++;
            m++;
        }
    }
    //--------------------------------------------------------------------------
    // report:
    return res;
}

//------------------------------------------------------------------------------
void test()
{

}

//------------------------------------------------------------------------------
int main()
{
    //test(); return 0;
    //DEBUG = true;
    //--------------------------------------------------------------------------
    int N, M, s, v, num;
    num = scanf("%d %d ", &N, &M);
    PAS PP(N);
    for (int i=0; i<N; ++i)
    {
        num = scanf("%d %d ", &s, &v);
        PP[i] = {v, s};
    }
    for (int m=0; m<M; ++m) num = scanf("%d ", &frame[m]);
    int res = greedy(N, PP, M);
    printf("%d\n", res);
    //--------------------------------------------------------------------------
    return 0;
}
//------------------------------------------------------------------------------
accuracy: 1
time_ms: 30
memory_kb: 4520
final_rank: 4

code_snippet: #include<bits/stdc++.h>
using namespace std;

using ll = long long;

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

    ll N,M;
    cin>>N>>M;
    vector<pair<ll,ll>> P(N);
    vector<ll> C(M);
    for(int i=0;i<N;i++)cin>>P[i].second>>P[i].first;
    for(int i=0;i<M;i++)cin>>C[i];
    sort(C.begin(),C.end());
    sort(P.begin(),P.end());
    reverse(C.begin(),C.end());
    reverse(P.begin(),P.end());
    ll an=0;
    ll L=0;
    for(int i=0;i<M;i++){
        while(L<N&&C[i]<P[L].second){
            L++;
        }
        if(L<N){
            an++;
            L++;
        }
    }
    cout<<an<<endl;
}
accuracy: 1
time_ms: 30
memory_kb: 5488
final_rank: 13

code_snippet: #include <iostream>
#include <vector>
#include <algorithm>
#include <functional>

using namespace std;
typedef pair<int, int> Pi;

int main() {
    int n, m, s, v;
    vector<int> c(100002);
    vector<Pi> vec;

    cin >> n >> m;
    for (int i = 0; i < n; i++) {
        cin >> s >> v;
        vec.push_back(Pi(v, s));
    }

    sort(vec.begin(), vec.end(), greater<Pi>());

    for (int i = 0; i < m; i++) {
        cin >> c[i];
    }

    sort(c.begin(), c.begin() + m, greater<int>());

    int mai = 0;
    for (int i = 0; mai < m && i < n; i++) {
        if (vec[i].second <= c[mai]) {
            mai++;
        }
    }

    cout << mai << endl;
    return 0;
}
accuracy: 1
time_ms: 70
memory_kb: 4552
final_rank: 12

code_snippet: #include "bits/stdc++.h"

#define REP(i,num) for(ll i=0;i<(num);++i)
#define FOR(i,c,num) for(ll (i)=(c);(i)<(num);++(i))
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;
using ull = unsigned long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=ll>
T in(){ T x; cin >> x; return (x); }
template<typename T=ll,typename C=vector<T>>
C vecin(int N){ C x(N);REP(i,N){ x[i]=in<T>(); }return x; }
template<typename T=ll,size_t N>
array<T,N> arrin(){array<T,N> x;REP(i,N){ x[i]=in<T>(); }return x;}

void vout(){ cout << endl; }
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){ cout << ' ' << h;vout(forward<Tail>(t)...); }
void out(){ cout << endl; }
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){ cout << h;vout(forward<Tail>(t)...); }

template<typename T>
bool chmax(T& a,T b){ if(a<b){ a=b;return true; }return false; }
template<typename T>
bool chmin(T& a,T b){ if(a>b){ a=b;return true; }return false; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	auto N=in(),M=in();
	vector<pair<ll,ll>> P(N);
	REP(i,N){
		P[i].first=in();
		P[i].second=in();
	}
	sort(ALL(P),[](const pair<ll,ll>& l,const pair<ll,ll>& r){return (l.second==r.second)?(l.first>r.first):(l.second>r.second);});
	vll C=vecin(M);
	sort(ALL(C));

	vll R(M,-1);
	REP(i,N){
		auto [S,V] = P[i];
		auto res = lower_bound(ALL(C),S);
		if(res==C.end()) continue;

		auto start = distance(C.begin(),res);
		res = upper_bound(R.begin()+start,R.end(),-1);
		if(res==R.begin()+start) continue;
		if(*(res-1)==-1){
			R[distance(R.begin(),res-1)]=i;
		}
	}
	ll A=0;
	REP(i,M){
		if(R[i]>=0) A++;
	}
	out(A);
	return 0;
}
accuracy: 1
time_ms: 40
memory_kb: 6260
final_rank: 16

code_snippet: #pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) { return (ull)rng() % B; }

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, m;
    cin >> n >> m;
    vector<pair<int, int>> v(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i].first >> v[i].second;
    }
    sort(v.begin(), v.end());
    vector<int> a(m);
    for (int i = 0; i < m; ++i) {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    auto slv = [&](int x) -> bool {
        int j = 0, mx = -1;
        priority_queue<int, vector<int>, greater<int>> pq;
        for (int i = m - x; i < m; ++i) {
            while (j < n and v[j].first <= a[i]) {
                pq.push(v[j].second);
                j += 1;
            }
            while (pq.size() and pq.top() < mx)
                pq.pop();
            if (pq.empty()) return false;
            mx = pq.top();
            pq.pop();
        }
        return true;
    };
    int l = 0, r = m + 1;
    while (r - l > 1) {
        int mid = (l + r) / 2;
        if (slv(mid)) l = mid;
        else r = mid;
    }
    cout << l << endl;
}
accuracy: 1
time_ms: 150
memory_kb: 4888
final_rank: 20

code_snippet: #line 1 "a.cpp"
#define PROBLEM ""
#line 2 "/home/kuhaku/home/github/algo/lib/template/template.hpp"
#pragma GCC target("sse4.2,avx2,bmi2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
template <class T, class U>
constexpr bool chmax(T &a, const U &b) {
    return a < (T)b ? a = (T)b, true : false;
}
template <class T, class U>
constexpr bool chmin(T &a, const U &b) {
    return (T)b < a ? a = (T)b, true : false;
}
constexpr std::int64_t INF = 1000000000000000003;
constexpr int Inf = 1000000003;
constexpr double EPS = 1e-7;
constexpr double PI = M_PI;
#line 3 "/home/kuhaku/home/github/algo/lib/template/macro.hpp"
#define FOR(i, m, n) for (int i = (m); i < int(n); ++i)
#define FORR(i, m, n) for (int i = (m)-1; i >= int(n); --i)
#define FORL(i, m, n) for (int64_t i = (m); i < int64_t(n); ++i)
#define rep(i, n) FOR (i, 0, n)
#define repn(i, n) FOR (i, 1, n + 1)
#define repr(i, n) FORR (i, n, 0)
#define repnr(i, n) FORR (i, n + 1, 1)
#define all(s) (s).begin(), (s).end()
#line 3 "/home/kuhaku/home/github/algo/lib/template/sonic.hpp"
struct Sonic {
    Sonic() {
        std::ios::sync_with_stdio(false);
        std::cin.tie(nullptr);
        std::cout << std::fixed << std::setprecision(20);
    }

    constexpr void operator()() const {}
} sonic;
#line 5 "/home/kuhaku/home/github/algo/lib/template/atcoder.hpp"
using namespace std;
using ll = std::int64_t;
using ld = long double;
template <class T, class U>
std::istream &operator>>(std::istream &is, std::pair<T, U> &p) {
    return is >> p.first >> p.second;
}
template <class T>
std::istream &operator>>(std::istream &is, std::vector<T> &v) {
    for (T &i : v) is >> i;
    return is;
}
template <class T, class U>
std::ostream &operator<<(std::ostream &os, const std::pair<T, U> &p) {
    return os << '(' << p.first << ',' << p.second << ')';
}
template <class T>
std::ostream &operator<<(std::ostream &os, const std::vector<T> &v) {
    for (auto it = v.begin(); it != v.end(); ++it) {
        os << (it == v.begin() ? "" : " ") << *it;
    }
    return os;
}
template <class Head, class... Tail>
void co(Head &&head, Tail &&...tail) {
    if constexpr (sizeof...(tail) == 0) std::cout << head << '\n';
    else std::cout << head << ' ', co(std::forward<Tail>(tail)...);
}
template <class Head, class... Tail>
void ce(Head &&head, Tail &&...tail) {
    if constexpr (sizeof...(tail) == 0) std::cerr << head << '\n';
    else std::cerr << head << ' ', ce(std::forward<Tail>(tail)...);
}
template <typename T, typename... Args>
auto make_vector(T x, int arg, Args... args) {
    if constexpr (sizeof...(args) == 0) return std::vector<T>(arg, x);
    else return std::vector(arg, make_vector<T>(x, args...));
}
void Yes(bool is_correct = true) {
    std::cout << (is_correct ? "Yes" : "No") << '\n';
}
void No(bool is_not_correct = true) {
    Yes(!is_not_correct);
}
void YES(bool is_correct = true) {
    std::cout << (is_correct ? "YES" : "NO") << '\n';
}
void NO(bool is_not_correct = true) {
    YES(!is_not_correct);
}
void Takahashi(bool is_correct = true) {
    std::cout << (is_correct ? "Takahashi" : "Aoki") << '\n';
}
void Aoki(bool is_not_correct = true) {
    Takahashi(!is_not_correct);
}
#line 3 "a.cpp"

int main(void) {
    int n, m;
    cin >> n >> m;
    vector<pair<int, int>> a(n);
    cin >> a;
    sort(all(a), [](auto l, auto r) {
        if (l.second == r.second)
            return l.first > r.first;
        return l.second > r.second;
    });
    vector<int> b(m);
    cin >> b;
    sort(all(b));
    reverse(all(b));

    int ans = 0;
    rep (i, n) {
        if (ans < m && a[i].first <= b[ans])
            ++ans;
    }
    co(ans);

    return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 4404
final_rank: 2

code_snippet: /* -*- coding: utf-8 -*-
 *
 * 0659.cc: 展覧会(Exhibition)
 */

#include<cstdio>
#include<algorithm>
#include<utility>
 
using namespace std;

/* constant */

const int MAX_N = 100000;
const int MAX_M = 100000;

/* typedef */

typedef pair<int,int> pii;

/* global variables */

int ss[MAX_N], vs[MAX_N], cs[MAX_M];
pii ps[MAX_N];

/* subroutines */

/* main */

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) scanf("%d%d", ss + i, vs + i);
  for (int i = 0; i < m; i++) scanf("%d", cs + i);

  for (int i = 0; i < n; i++) ps[i] = pii(vs[i], ss[i]);
  sort(ps, ps + n);
  sort(cs, cs + m);

  int cnt = 0;
  for (int i = n - 1, j = m - 1; i >= 0 && j >= 0; i--)
    if (ps[i].second <= cs[j])
      cnt++, j--;

  printf("%d\n", cnt);
  
  return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 4912
final_rank: 6

code_snippet: #include<bits/stdc++.h>
using namespace std;
typedef pair<int, int> Pi;
int main(){
    int n, m, s, v, c[100002];
    vector<Pi> vec;
    cin >> n >> m;
    for(int i=0;i<n;i++){
        cin >> s >> v;
        vec.push_back(Pi(v, s));
    }
    sort(vec.begin(), vec.end(), greater<Pi>());
    for(int i=0;i<m;i++) cin >> c[i];
    sort(c, c+m, greater<int>());
    int mai=0;
    for(int i=0;mai<m&&i<n;i++){
        if(vec[i].second <= c[mai]) mai++;
    }
    cout << mai << endl;
    return(0);
}
accuracy: 1
time_ms: 90
memory_kb: 4156
final_rank: 11

code_snippet: #include <iostream>
#include <cstdlib>
using namespace std;

typedef struct SandV_{
    int S;
    int V;
} SandV;


int compareC (const void * a, const void * b)
{
  return ( *(int*)b - *(int*)a );
}

int compareSV (const void * a, const void * b)
{
  SandV *SV1=(SandV*) a;
  SandV *SV2=(SandV*) b;
  if(SV1->V < SV2->V) return 1;
  else if (SV1->V > SV2->V) return -1;
  
  if(SV1->S < SV2->S) return 1;
  else if (SV1->S > SV2->S) return -1;
  return 0;
}

int main(void){
    // Your code here!
    int N,M,S,V;
    cin >> N >>M;

    SandV arraySV[N];
    int C[M];
    
    for(int i=0;i<N;i++){
        cin >>  S >> V;
        arraySV[i].S=S;
        arraySV[i].V=V;
    }   
    
    for(int j=0;j<M;j++){
        cin >>C[j];
    }
    
    qsort(arraySV, N, sizeof(SandV), compareSV);
    qsort(C, M, sizeof(int), compareC);
    
    int count=0;
    int countM=0;
    for(int i=0;i<N;i++){
        if(C[countM]>=arraySV[i].S){
            count+=1;
            countM++;
            if(countM>=M){
                break;
            }
        }
    }
    cout <<count <<endl;
}
accuracy: 1
time_ms: 120
memory_kb: 4872
final_rank: 19

code_snippet: #include <bits/stdc++.h>
using namespace std;
int main(){
    int N,M;
    cin>>N>>M;
    vector<pair<int,int> > X1(N);
    vector<int> X2(M);
    for(int i=0;i<N;i++){
        cin>>X1.at(i).second>>X1.at(i).first;
    }
    for(int i=0;i<M;i++){
        cin>>X2.at(i);
    }
    
    sort(X1.begin(),X1.end());
    sort(X2.begin(),X2.end());
  
    
    int count=0;
    int i=M-1;
    int j=N-1;
    while(!X1.empty()&&!X2.empty()){
       if(X1.at(j).second>X2.at(i)){
           X1.pop_back();
           j--;
       } 
       else{
           count++;
           X1.pop_back();
           X2.pop_back();
           i--;
           j--;
       }
    }
    
    cout<<count<<endl;
}
accuracy: 1
time_ms: 100
memory_kb: 3896
final_rank: 10

code_snippet: #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

int main() {
  int n, m;
  cin >> n >> m;

  vector<pair<int, int>> ps(n);
  for (auto&& e : ps)
    cin >> e.first >> e.second;
  sort(ps.begin(), ps.end(), [](pair<int, int> l, pair<int, int> r) {
    if (l.second == r.second)
      return l.first < r.first;
    return l.second < r.second;
  });

  vector<int> cs(m);
  for (auto&& e :  cs)
    cin >> e; 
  sort(cs.begin(), cs.end());

  int p = n - 1, c = m - 1, count = 0;
  while (p >= 0 && c >= 0)
    if (cs[c] >= ps[p].first)
      --c, --p, ++count;
    else
      --p;
  cout << count << endl;
  return 0;
}
accuracy: 1
time_ms: 70
memory_kb: 4308
final_rank: 7

code_snippet: #include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <cstddef>
#include <cstdint>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <memory>
#include <numeric>
#include <optional>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

/* macro */

#define rep(i, a, n) for (int i = (int)(a); i < (int)(n); i++)
#define rrep(i, a, n) for (int i = ((int)(n - 1)); i >= (int)(a); i--)
#define Rep(i, a, n) for (i64 i = (i64)(a); i < (i64)(n); i++)
#define RRep(i, a, n) for (i64 i = ((i64)(n - i64(1))); i >= (i64)(a); i--)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define Bit(n) (1LL << (n))

/* macro end */

/* template */

namespace ebi {

#ifdef LOCAL
#define debug(...)                                                      \
    std::cerr << "LINE: " << __LINE__ << "  [" << #__VA_ARGS__ << "]:", \
        debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

void debug_out() { std::cerr << std::endl; }

template <typename Head, typename... Tail>
void debug_out(Head h, Tail... t) {
    std::cerr << " " << h;
    if (sizeof...(t) > 0) std::cout << " :";
    debug_out(t...);
}

template <typename T1, typename T2>
std::ostream &operator<<(std::ostream &os, const std::pair<T1, T2> &pa) {
    return os << pa.first << " " << pa.second;
}

template <typename T1, typename T2>
std::istream &operator>>(std::istream &os, std::pair<T1, T2> &pa) {
    return os >> pa.first >> pa.second;
}

template <typename T>
std::ostream &operator<<(std::ostream &os, const std::vector<T> &vec) {
    for (std::size_t i = 0; i < vec.size(); i++)
        os << vec[i] << (i + 1 == vec.size() ? "" : " ");
    return os;
}

template <typename T>
std::istream &operator>>(std::istream &os, std::vector<T> &vec) {
    for (T &e : vec) std::cin >> e;
    return os;
}

template <typename T>
std::ostream &operator<<(std::ostream &os, const std::optional<T> &opt) {
    if (opt) {
        os << opt.value();
    } else {
        os << "invalid value";
    }
    return os;
}

using std::size_t;
using i32 = std::int32_t;
using u32 = std::uint32_t;
using i64 = std::int64_t;
using u64 = std::uint64_t;

template <class T, T init>
auto make_vector(int n) {
    return std::vector<T>(n, init);
}

template <class T, T init, typename Head, typename... Tail>
auto make_vector(Head n, Tail... ts) {
    return std::vector(n, make_vector<T, init>(ts...));
}

template <class T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template <class T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template <class T>
T pow(T x, i64 n) {
    T res = 1;
    while (n > 0) {
        if (n & 1) res = res * x;
        x = x * x;
        n >>= 1;
    }
    return res;
}

template <class T>
T mod_pow(T x, i64 n, i64 mod) {
    T res = 1;
    while (n > 0) {
        if (n & 1) res = (res * x) % mod;
        x = (x * x) % mod;
        n >>= 1;
    }
    return res;
}

template <class T>
T scan() {
    T val;
    std::cin >> val;
    return val;
}

template <class T>
struct Edge {
    int to;
    T cost;
    Edge(int _to, T _cost = 1) : to(_to), cost(_cost) {}
};

template <class T>
struct Graph : std::vector<std::vector<Edge<T>>> {
    using std::vector<std::vector<Edge<T>>>::vector;
    void add_edge(int u, int v, T w, bool directed = false) {
        (*this)[u].emplace_back(v, w);
        if (directed) return;
        (*this)[v].emplace_back(u, w);
    }
};

struct graph : std::vector<std::vector<int>> {
    using std::vector<std::vector<int>>::vector;
    void add_edge(int u, int v, bool directed = false) {
        (*this)[u].emplace_back(v);
        if (directed) return;
        (*this)[v].emplace_back(u);
    }
};

constexpr i64 LNF = std::numeric_limits<i64>::max() / 4;

constexpr int INF = std::numeric_limits<int>::max() / 2;

const std::vector<int> dy = {1, 0, -1, 0, 1, 1, -1, -1};
const std::vector<int> dx = {0, 1, 0, -1, 1, -1, 1, -1};

}  // namespace ebi

namespace ebi {

void main_() {
    int n,m;
    std::cin >> n >> m;
    std::vector<std::pair<int,int>> sv(n);
    std::cin >> sv;
    std::sort(all(sv), [&](auto a, auto b) {
        if(a.second == b.second) return a.first < b.first;
        return a.second < b.second;
    });
    std::vector<int> cs(m);
    std::cin >> cs;
    std::sort(all(cs));
    int ok = 0, ng = m+1;
    while(std::abs(ok - ng) > 1) {
        int mid = (ok + ng)/2;
        int idx = m - mid;
        for(auto [s, v]: sv) {
            if(idx == m) break;
            if(s <= cs[idx]) {
                idx++;
            }
        }
        if(idx == m) {
            ok = mid;
        }
        else {
            ng = mid;
        }
    }
    std::cout << ok << '\n';
}

}  // namespace ebi

int main() {
    std::cout << std::fixed << std::setprecision(15);
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    int t = 1;
    // std::cin >> t;
    while (t--) {
        ebi::main_();
    }
    return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 4424
final_rank: 3

code_snippet: // g++ -std=c++17 -DDEV=1 main.cpp
#include <stdio.h>
#include <cassert>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <algorithm>

using std::cin;
using std::cout;
using std::endl;
using std::terminate;
using std::vector;
using std::string;
using std::set;
using std::map;
using std::sort;
using std::pair;
using std::make_pair;

#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define bit(n, k) ((n >> k) & 1)

class Program {

private:

    bool min(int &a, const int b) {
        if (a > b) {
            a = b;
            return true;
        } else {
            return false;
        }
    }

public:

    Program() {
    }

    // 額縁の大きさ: 左 <= 右
    // 価値: 左 <= 右
    void solve() {
        int n, m; cin >> n >> m;

        vector<pair<int, int>> ps;
        rep(i, 0, n) {
            int s, v; cin >> s >> v;
            ps.push_back(make_pair(v, s));
        }

        sort(ps.begin(), ps.end(), std::greater<std::pair<int,int>>());

        // for (auto [value, size] : ps) {
        //     cout << size << "," << value << endl;
        // }

        vector<int> cs;
        cs.resize(m);
        rep(i, 0, m) {
            cin >> cs[i];
        }

        sort(cs.begin(), cs.end(), std::greater<int>());

        int ans = 0, k = 0;
        rep(j, 0, cs.size()) {
            bool found = false;
            rep(i, k, ps.size()) {
                if (cs[j] >= ps[i].second) {
                    k = i+1;
                    found = true;
                    ans++;
                    break;
                }
            }

            if (!found) {
                // 残りの額縁の最大より残りの絵のほうが大きい
                break;
            }
        }

        cout << ans << endl;
    }
};

int main() {

#ifdef DEV
    std::ifstream in("input");
    cin.rdbuf(in.rdbuf());

    int t; cin >> t;
    for (int x = 1; x <= t; ++x) {
        Program p;
        p.solve();
    }
#else
    Program p;
    p.solve();
#endif

    return 0;
}
accuracy: 1
time_ms: 70
memory_kb: 4408
final_rank: 8

code_snippet: #include <bits/stdc++.h>
using namespace std;
const long long MOD1 = 1000000007;
const long long MOD2 = 998244353;
typedef long long ll;
//typedef int ll;
typedef pair<long long, long long> P;
const long long INF = 1000000010;
template <typename T>
void input_arr(vector<T>& A, ll N) {
	for (ll i = 0; i < N; i++) {
		cin >> A[i];
	}
}
template <typename T, typename Q>
void input_arr(vector<pair<T, Q>>& A, ll N) {
	for (ll i = 0; i < N; i++) {
		cin >> A[i].first >> A[i].second;
	}
}
template <typename T>
void input_arr(vector<vector<T>>& A, ll H, ll W) {
	for (ll i = 0; i < H; i++) {
		for (ll j = 0; j < W; j++) {
			cin >> A[i][j];
		}
	}
}
void solve() {
    ll N, M; cin >> N >> M;
    vector<P>A(N);
    for (ll i = 0; i < N; i++) cin >> A[i].second >> A[i].first;
    sort(A.begin(), A.end(), greater<P>());
    vector<ll>C(M); input_arr(C, M);
    sort(C.begin(), C.end(), greater<ll>());
    ll ans = 0, pos = 0;
    for (ll i = 0; i < N; i++) {
        if (pos >= M) break;
        if (A[i].second <= C[pos]) {
            ans++;
            pos++;
        }
    }
    cout << ans << endl;
}
int main() {
    ll T = 1; //cin >> T;
    while (T--) solve();
}
accuracy: 1
time_ms: 80
memory_kb: 5492
final_rank: 17

code_snippet: #include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define drep(i,j,n) for(int i=0;i<(int)(n-1);i++)for(int j=i+1;j<(int)(n);j++)
#define trep(i,j,k,n) for(int i=0;i<(int)(n-2);i++)for(int j=i+1;j<(int)(n-1);j++)for(int k=j+1;k<(int)(n);k++)
#define codefor int test;scanf("%d",&test);while(test--)
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define yes(ans) if(ans)printf("yes\n");else printf("no\n")
#define Yes(ans) if(ans)printf("Yes\n");else printf("No\n")
#define YES(ans) if(ans)printf("YES\n");else printf("NO\n")
#define popcount(v) __builtin_popcountll(v)
#define vector2d(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define vector3d(type,name,h,w,...) vector<vector<vector<type>>>name(h,vector<vector<type>>(w,vector<type>(__VA_ARGS__)))
using namespace std;
using ll = long long;
template<class T> using rpriority_queue = priority_queue<T, vector<T>, greater<T>>;
const int MOD=1000000007;
const int MOD2=998244353;
const int INF=1<<30;
const ll INF2=1LL<<60;
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T,class L>void scan(pair<T, L>& p){scan(p.first);scan(p.second);}
template<class T,class U,class V>void scan(tuple<T,U,V>& p){scan(get<0>(p));scan(get<1>(p));scan(get<2>(p));}
template<class T, size_t size> void scan(array<T, size>& a){ for(auto&& i : a) scan(i);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T,class L>void print(const pair<T, L>& p){print(p.first);putchar(' ');print(p.second);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}
ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; }
ll modpow(ll a, ll b, ll p){ ll ans = 1; while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; }
ll modinv(ll a, ll m) {ll b = m, u = 1, v = 0;while (b) {ll t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}
ll updivide(ll a,ll b){return (a+b-1)/b;}
int msb(ll v){return 63-__builtin_clzll(v);}
template<class T> void chmax(T &a,const T b){if(b>a)a=b;}
template<class T> void chmin(T &a,const T b){if(b<a)a=b;}

int main(){
    INT(n,m);
    priority_queue<pair<int,int>> pq;
    vector<int> c(m);
    int s,v,ans=0;
    rep(i,n){
        in(s,v);
        pq.push({v,s});
    }
    in(c);
    sort(rall(c));
    rep(i,m){
        while(!pq.empty()&&pq.top().second>c[i]){
            pq.pop();
        }
        if(pq.empty())break;
        ans++;
        pq.pop();
    }
    out(ans);
}
accuracy: 1
time_ms: 30
memory_kb: 4584
final_rank: 5

code_snippet: #include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 4000000000000000000 //オーバーフローに注意
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;




#define SIZE 100005

struct Info{

	bool operator<(const struct Info& arg) const{
		if(value != arg.value){

			return value < arg.value;
		}else{

			return S < arg.S; //同じサイズなら、大きいものから割り当てる
		}

	}

	ll S,value;
};

ll C[SIZE];
Info info[SIZE];

int main(){

	ll N,M;
	scanf("%lld %lld",&N,&M);

	for(ll i = 0; i < N; i++){

		scanf("%lld %lld",&info[i].S,&info[i].value);
	}
	sort(info,info+N);

	for(ll i = 0; i < M; i++){

		scanf("%lld",&C[i]);
	}
	sort(C,C+M);

	int info_index = N-1;

	int ans = 0;

	/*額縁の降順に見ていき、価値の降順に絵画を割り当てる
	 * 同じ価値ならば、大きい絵画から割り当てる
	 *
	 * */
	for(int i = M-1; i >= 0; i--){
		while(info_index >= 0 && info[info_index].S > C[i]){

			info_index--;
		}
		if(info_index < 0)break;

		ans++;
		info_index--;
		if(info_index < 0)break;
	}

	printf("%d\n",ans);

	return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 5648
final_rank: 15

code_snippet: #include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 4000000000000000000 //オーバーフローに注意
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define SIZE 100005

struct Info{

	bool operator<(const struct Info& arg) const{

		if(V != arg.V){
			return V < arg.V;
		}else{

			return S < arg.S;
		}
	}

	ll S,V;
};

ll C[SIZE];
Info info[SIZE];

int main(){

	int N,M;

	scanf("%d %d",&N,&M);

	for(int i = 0; i < N; i++){

		scanf("%lld %lld",&info[i].S,&info[i].V);
	}

	for(int i = 0; i < M; i++){

		scanf("%lld",&C[i]);
	}

	sort(info,info+N);
	sort(C,C+M);

	ll ans = 0;
	int index = N-1;

	for(int i = M-1; i >= 0; i--){

		while(index >= 0 && info[index].S > C[i])index--;
		if(index == -1)break;


		ans++;
		//printf("ans:%lld index:%d\n",ans,index);
		index--;
	}

	printf("%lld\n",ans);

	return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 5628
final_rank: 14

code_snippet: #include<cstdio>
#include<algorithm>
#include<functional>
using namespace std;
typedef pair<int,int> P;
P p[100001]; 
int c[100001];
int main(void)
{
	int n,m,cnt=0,x,s,v,i,j,ans=0;
	scanf("%d%d",&n,&m);
	for(i=0;i<n;i++){
		scanf("%d%d",&s,&v);
		p[i].first=v;
		p[i].second=s;
	}
	for(i=0;i<m;i++)	scanf("%d",&c[i]);
	sort(p,p+n,greater<P>());
	sort(c,c+m,greater<int>());
	x=0;
	for(i=0;i<n;i++){
		if(p[i].second<=c[x]){
			cnt++;
			ans=max(ans,cnt);
			x++;
		}
	}
	printf("%d\n",ans);
	return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 3976
final_rank: 1

code_snippet: #include<iostream>
#include<string>
#include<algorithm>    
#include<cmath>
#include<ctime>
#include<map>
#include<vector>
#include<math.h>
#include<stdio.h>
#include<stack>
#include<queue>
#include<tuple>
#include<cassert>
#include<set>
#include<bitset>
#include<functional>
#include <fstream>
//#include<bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define rep(i, x) for(ll i = 0; i < x; i++)
#define rep2(i, x) for(ll i = 1; i <= x; i++)
#define all(a) (a).begin(),(a).end()
#define puts(x) cout << (x) << "\n"
using ll = long long;
using ld = long double;
using namespace std;
const ll INF = 10000000000000000;
const int intINF = 1000000000;
const ll mod = 1000000007;
const ll MOD = 998244353;
const ld pi = 3.141592653589793238;

bool isprime(int p) {
	if (p == 1) return false;
	for (int i = 2; i < p; i++) {
		if (p % i == 0) return false;
	}
	return true;
}
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (a % b == 0)return b;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}
ll keta(ll n) {
	ll res = 0;
	while (n >= 1) {
		res += n % 10; n /= 10;
	}
	return res;
}
ll modpow(ll x, ll y) {
	ll res = 1;
	while (y) {
		if (y % 2) { res *= x; res %= mod; }
		x = x * x % mod; y /= 2;
	}
	return res;
}
ll nCk(ll n, ll k) {
	ll a = 1, b = 1;
	for (int h = n - k + 1; h <= n; h++) { a *= h; a %= mod; }
	for (int h = 1; h <= k; h++) { b *= h; b %= mod; }
	return a * modpow(b, mod - 2) % mod;
}
//printf("%.10f\n", n);
typedef pair <ll, ll> P;
ll dx[4] = { 1, 0, -1, 0 }, dy[4] = { 0, 1, 0, -1 };
struct edge { ll to, cost; };
struct status {
	bool ok;
	ll x;
	ll y;
	ll cost;

	bool operator<(const status& rhs) const { return cost < rhs.cost; };
	bool operator>(const status& rhs) const { return cost > rhs.cost; };
};

signed main() {
	ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
	//cout << fixed << setprecision(15);

	//input
	ll n, m; cin >> n >> m;
	vector<P> vs(n);
	rep(i, n) { cin >> vs[i].second >> vs[i].first; }
	sort(all(vs)); reverse(all(vs));
	vector<ll> large(m);
	rep(i, m) { cin >> large[i]; }
	sort(all(large)); reverse(all(large));
	ll ima = 0, ans = 0;
	rep(i, m) {
		for (int j = ima; j < n; j++) {
			if (vs[j].second <= large[i]) { ans++; break; }
			ima++;
		}
		ima++;
	}
	cout << ans << endl;
	return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 5216
final_rank: 9