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<cstdio>
#include<algorithm>
#include<map>
std::map<int,long long> u,d;
std::pair<int,int> a[100000];
int main()
{
long long r=0;
long long uv,dv;
int i,n,m;
scanf("%d%d",&n,&m);
for(i=0;i<n;i++)scanf("%d%d",&a[i].first,&a[i].second);
std::sort(a,a+n);
for(i=0;i<n;i++)
{
if(u.find(a[i].first)==u.end())uv=0;
else uv=u[a[i].first];
if(d.find(a[i].second)==d.end())dv=0;
else dv=d[a[i].second];
uv+=std::abs(a[i].first-a[i].second)+m;
dv+=std::abs(a[i].first-a[i].second)+m;
if(u.find(a[i].first)==u.end()||u[a[i].first]<dv)u[a[i].first]=dv;
if(d.find(a[i].second)==d.end()||d[a[i].second]<uv)d[a[i].second]=uv;
r=std::max(r,std::max(uv,dv));
}
printf("%lld",r);
}
# | 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... |