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 <stdio.h>
#include <stdlib.h>
#include <algorithm>
using namespace std;
struct data{
int t,d;
bool operator<(const data&r)const{
if(t==r.t)return d<r.d;
return t<r.t;
}
}a[100010];
int tt[100010],td[100010],tn,dn;
long long Dt[100010],Dd[100010],t,d,s,ans;
int bsearch(int s,int e,int p,int t){
if(s==e)return s;
int m=(s+e)/2;
if(t&&p<=tt[m])return bsearch(s,m,p,t);
else if(!t&&p<=td[m])return bsearch(s,m,p,t);
else return bsearch(m+1,e,p,t);
}
int main(){
int i,n,l,x,y;
scanf("%d%d",&n,&l);
for(i=0;i<n;++i){
scanf("%d%d",&a[i].t,&a[i].d);
tt[tn++]=a[i].t;
td[dn++]=a[i].d;
}
sort(a,a+n);
sort(tt,tt+tn);
sort(td,td+tn);
for(i=0;i<n;++i){
x=bsearch(0,tn,a[i].t,1);
y=bsearch(0,dn,a[i].d,0);
s=(long long)l+abs(a[i].t-a[i].d);
t=max(Dt[x],Dd[y]+s);
d=max(Dd[y],Dt[x]+s);
Dt[x]=t;
Dd[y]=d;
}
for(i=0;i<tn;++i)ans=max(ans,Dt[i]);
for(i=0;i<dn;++i)ans=max(ans,Dd[i]);
printf("%lld",ans);
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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |