#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define st first
#define nd second
typedef long long ll;
typedef long double ld;
const ll I = 1'000'000'000'000'000'000LL;
const int II = 2'000'000'000;
const ll M = 1'000'000'007LL;
const int N = 1'000'007;
pair<int, int> tab[N];
int siz[N];
bool Check(int n, int m, int il)
{
int j = 0, prev = 0;
multiset<int> cur;
multiset<int>::iterator it;
for(int i = m - il + 1; i <= m; ++i)
{
while(j < n && tab[j + 1].st <= siz[i])
{
++j;
cur.insert(tab[j].nd);
}
it = cur.lower_bound(prev);
if(it == cur.end()) return 0;
prev = *it;
cur.erase(it);
}
return 1;
}
int BS(int n, int m)
{
int p = 0, k = m, s;
while(p < k)
{
s = (p + k + 1) / 2;
if(Check(n, m, s))
p = s;
else
k = s - 1;
}
return p;
}
void Solve()
{
int n, m;
cin >> n >> m;
for(int i = 1; i <= n; ++i)
cin >> tab[i].st >> tab[i].nd;
sort(tab + 1, tab + 1 + n);
for(int i = 1; i <= m; ++i)
cin >> siz[i];
sort(siz + 1, siz + 1 + m);
int ans = BS(n, m);
cout << ans << "\n";
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
//int t; cin >> t;
//while(t--)
Solve();
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |