Submission #128538

#TimeUsernameProblemLanguageResultExecution timeMemory
128538qkxwsmExhibition (JOI19_ho_t2)C++14
100 / 100
80 ms5416 KiB
//reading is hard

#include <bits/stdc++.h>

using namespace std;

template<class T, class U>
void ckmin(T &a, U b)
{
	if (a > b) a = b;
}
template<class T, class U>
void ckmax(T &a, U b)
{
	if (a < b) a = b;
}

#define MP make_pair
#define PB push_back
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define FOR(i, a, b) for (auto i = (a); i < (b); i++)
#define FORD(i, a, b) for (auto i = (a) - 1; i >= (b); i--)
#define SZ(x) ((int) ((x).size()))
#define ALL(x) (x).begin(), (x).end()
#define INF 1000000007
#define LLINF 2696969696969696969ll
#define MAXN 100013

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef vector<pll> vpl;

int N, M;
pii arr[MAXN];
int lim[MAXN];
vi dp;

bool check(int x)
{
	//you need smth 0...x - 1
	vi nums;
	FOR(i, 0, x)
	{
		nums.PB(lim[M - 1 - i]);
	}
	reverse(ALL(nums));
	// for (int x : nums)
	// {
	// 	cerr << x << ' ';
	// }
	// cerr << endl;
	int iter = 0;
	FOR(i, 0, x)
	{
		while(iter < N && arr[iter].se > nums[i]) iter++;
		iter++;
	}
	return (iter <= N);
}

int32_t main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> N >> M;
	FOR(i, 0, N)
	{
		cin >> arr[i].se >> arr[i].fi;
	}
	sort(arr, arr + N);
	FOR(i, 0, M)
	{
		cin >> lim[i];
	}
	sort(lim, lim + M);
	int lo = 0, hi = min(N, M);
	while(hi > lo)
	{
		int mid = (hi + lo + 1) >> 1;
		if (check(mid)) lo = mid;
		else hi = mid - 1;
	}
	cout << lo << '\n';
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...