Submission #8020

#TimeUsernameProblemLanguageResultExecution timeMemory
8020jhs7jhs막대기 (KOI13_game)C++98
100 / 100
60 ms5108 KiB
#include<stdio.h> #include<vector> #include<algorithm> using namespace std; pair<int,int> a[100000]; vector<int> r; int n,l; long long rmax[100000]={0},dp[100000][2]={0},ans=0; int main() { int i,p; long long t; scanf("%d%d",&n,&l); for(i=0;i<n;i++){ scanf("%d%d",&a[i].first,&a[i].second); r.push_back(a[i].second); } sort(r.begin(),r.end()); sort(a,a+n); for(i=0;i<n;i++){ if(i==0 || a[i].first!=a[i-1].first) t=0; dp[i][1] = t + (long long)(l + abs(a[i].first-a[i].second)); p = lower_bound(r.begin(),r.end(),a[i].second) - r.begin(); dp[i][0] = rmax[p] + (long long)(l + abs(a[i].first-a[i].second)); if(rmax[p] < dp[i][1]) rmax[p] = dp[i][1]; if(t<dp[i][0]) t=dp[i][0]; if(ans < dp[i][0]) ans = dp[i][0]; if(ans < dp[i][1]) ans = dp[i][1]; } printf("%lld\n",ans); return 0; }
#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...