#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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
4336 KB |
Output is correct |
2 |
Correct |
0 ms |
4336 KB |
Output is correct |
3 |
Correct |
0 ms |
4336 KB |
Output is correct |
4 |
Correct |
0 ms |
4336 KB |
Output is correct |
5 |
Correct |
0 ms |
4336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
24 ms |
4724 KB |
Output is correct |
2 |
Correct |
16 ms |
4724 KB |
Output is correct |
3 |
Correct |
44 ms |
5108 KB |
Output is correct |
4 |
Correct |
48 ms |
5108 KB |
Output is correct |
5 |
Correct |
52 ms |
5108 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
4336 KB |
Output is correct |
2 |
Correct |
0 ms |
4336 KB |
Output is correct |
3 |
Correct |
0 ms |
4336 KB |
Output is correct |
4 |
Correct |
0 ms |
4336 KB |
Output is correct |
5 |
Correct |
0 ms |
4336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
4336 KB |
Output is correct |
2 |
Correct |
0 ms |
4336 KB |
Output is correct |
3 |
Correct |
0 ms |
4336 KB |
Output is correct |
4 |
Correct |
0 ms |
4336 KB |
Output is correct |
5 |
Correct |
0 ms |
4336 KB |
Output is correct |
6 |
Correct |
0 ms |
4336 KB |
Output is correct |
7 |
Correct |
0 ms |
4336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
4336 KB |
Output is correct |
2 |
Correct |
8 ms |
4336 KB |
Output is correct |
3 |
Correct |
28 ms |
4724 KB |
Output is correct |
4 |
Correct |
60 ms |
5108 KB |
Output is correct |
5 |
Correct |
60 ms |
5108 KB |
Output is correct |
6 |
Correct |
56 ms |
5108 KB |
Output is correct |
7 |
Correct |
52 ms |
5108 KB |
Output is correct |
8 |
Correct |
56 ms |
5108 KB |
Output is correct |
9 |
Correct |
4 ms |
4336 KB |
Output is correct |
10 |
Correct |
4 ms |
4336 KB |
Output is correct |
11 |
Correct |
60 ms |
5108 KB |
Output is correct |
12 |
Correct |
52 ms |
5108 KB |
Output is correct |