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;
#define ll long long
ll n,q;
struct dt{
ll s,v;
};
ll b[1000006],d,maxs=0;
bool cmp(dt x,dt y)
{
if(x.v<y.v)return true;
if(x.v==y.v)
{
return x.s<y.s;
}
return false;
}
dt a[1000006];
void tinh(ll x,ll y,ll z)
{
if(y>n||x>q)return;
if(a[y].s<=b[x]&&a[y].v>=z)
{
ll t=z;
z=a[y].v;
d++;
maxs=max(maxs,d);
//cout<<a[y].s<<" "<<b[x]<<"\n";
tinh(x+1,y+1,z);
d--;
z=t;
}
if(a[y].v<z)
tinh(x,y+1,z);
if(a[y].s>b[x])
tinh(x+1,y,z);
}
int main()
{
cin>>n>>q;
for(ll i=1;i<=n;i++)
cin>>a[i].s>>a[i].v;
sort(a+1,a+n+1,cmp);
for(ll i=1;i<=q;i++)
cin>>b[i];
sort(b+1,b+q+1);
for(ll i=1;i<=n;i++)
tinh(1,i,0);
cout<<maxs;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |