Submission #7416

#TimeUsernameProblemLanguageResultExecution timeMemory
7416gs13068막대기 (KOI13_game)C++98
100 / 100
164 ms8856 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...