#include<bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
using namespace std;
const int N=1e5+5;
int n,m,c[N];
pii a[N],f[N],ST[8*N];
void update(int id,int l,int r,int pos,pii val)
{
if(pos<l||pos>r) return ;
if(l==r)
{
ST[id]=max(ST[id],val);
return ;
}
int mid=(l+r)/2;
update(id*2,l,mid,pos,val);
update(id*2+1,mid+1,r,pos,val);
ST[id]=max(ST[id*2],ST[id*2+1]);
}
pii get (int id,int l,int r,int L,int R)
{
if (r<L||R<l) return mp(-1e9,0);
if (L<=l&&r<=R) return ST[id];
int mid=(l+r)/2;
return max (get(id*2,l,mid,L,R),get(id*2+1,mid+1,r,L,R));
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin>>n>>m;
vector<int>val;
for(int i=1;i<=n;i++)
{
cin>>a[i].fi>>a[i].se;
val.push_back(a[i].se);
}
for(int i=1;i<=m;i++) cin>>c[i];
sort(val.begin(),val.end());
val.erase(unique(val.begin(),val.end()),val.end());
int sz=val.size();
for(int i=1;i<=n;i++) a[i].se=lower_bound(val.begin(),val.end(),a[i].se)-val.begin()+1;
sort(a+1,a+n+1);
sort(c+1,c+m+1);
for(int i=1;i<8*N;i++) ST[i]=mp(-1e9,0);
pii res=mp(0,0);
for(int i=1;i<=n;i++)
{
if(a[i].fi>c[m]) continue;
int id=lower_bound(c+1,c+m+1,a[i].fi)-c;
f[i]=mp(1,-id);
pii cur=get(1,1,sz,1,a[i].se);
int pos=max(-cur.se+1,id);
if(pos<=m) f[i]=max(f[i],mp(cur.fi+1,-pos));
update(1,1,sz,a[i].se,f[i]);
res=max(res,f[i]);
//cout<<f[i].fi<<' '<<f[i].se<<'\n';
}
cout<<res.fi;
}
/*
3 4
10 20
5 1
3 5
4 6 10 4
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
6656 KB |
Output is correct |
2 |
Correct |
5 ms |
6596 KB |
Output is correct |
3 |
Correct |
5 ms |
6656 KB |
Output is correct |
4 |
Correct |
5 ms |
6656 KB |
Output is correct |
5 |
Incorrect |
5 ms |
6656 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
6656 KB |
Output is correct |
2 |
Correct |
5 ms |
6596 KB |
Output is correct |
3 |
Correct |
5 ms |
6656 KB |
Output is correct |
4 |
Correct |
5 ms |
6656 KB |
Output is correct |
5 |
Incorrect |
5 ms |
6656 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
6656 KB |
Output is correct |
2 |
Correct |
5 ms |
6596 KB |
Output is correct |
3 |
Correct |
5 ms |
6656 KB |
Output is correct |
4 |
Correct |
5 ms |
6656 KB |
Output is correct |
5 |
Incorrect |
5 ms |
6656 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |