#include<bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("avx2")
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define plx pair<ll,int>
#define f first
#define s second
#define pb push_back
#define all(x) x.begin(),x.end()
#define vi vector<int>
#define vvi vector<vi>
#define pp pair<ll,int>
#define ub(x,i) upper_bound(all(x),i)-x.begin()
using namespace std;
const int mxn=1e5+5;
vector<int>g[mxn];
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);
int n,m;cin>>n>>m;
pii a[n];int c[n];
for(int i=0;i<n;i++)cin>>a[i].f>>a[i].s;
for(int i=0;i<m;i++)cin>>c[i];
sort(a,a+n);sort(c,c+m);
vector<int>vec;vec.pb(a[0].s);
g[1].pb(0);
for(int i=1;i<n;i++){
int id=upper_bound(all(vec),a[i].s)-vec.begin();
if(id==vec.size()){
vec.pb(a[i].s);
}else vec[id]=a[i].s;
g[id+1].pb(i);
}
int l=0,r=m;
while(l<r){
int md=(l+r+1)>>1;
int cur=m-1;
int mx=2e9;
bool ok=1;
for(int i=md;i>=1;i--){
int mem=-1;
for(auto it : g[i]){
if(c[cur]>=a[it].f&&a[it].s<=mx)mem=max(a[it].s,mem);
}
if(mem==-1){ok=0;break;}
cur--;
mx=mem;
}
if(ok)l=md;
else r=md-1;
}cout<<l;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |