This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int N=1e5+3;
int nr[N],M[N];
pair<int,int>T[N];
int n,m;
int bs(int x,int dl)
{
int pocz=0,kon=dl+1;
while(pocz+1<kon)
{
int mid=(pocz+kon)/2;
if(nr[mid]>x)kon=mid;
else pocz=mid;
}
return kon;
}
bool f(int x)
{
for(int i=1;i<=n;i++)nr[i]=1e9;
int maks=0;
for(int i=1;i<=n;i++)
{
int a=T[i].second,ind=bs(a,maks);
if(a<=M[ind+x])
{
nr[ind]=min(a,nr[ind]);
maks=max(maks,ind);
}
if(maks+x==m)return true;
}
return false;
}
int main()
{
cin>>n>>m;
for(int i=1;i<=n;i++)
{
cin>>T[i].second>>T[i].first;
}
sort(T+1,T+n+1);
for(int i=1;i<=m;i++)cin>>M[i];
sort(M+1,M+m+1);
int pocz=0,kon=min(m,n)+1;
while(pocz+1<kon)
{
int mid=(pocz+kon)/2;
if(f(m-mid))pocz=mid;
else kon=mid;
}
cout<<pocz;
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... |