#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
using namespace std;
typedef pair <int,int> ppair;
pair <int,int> A[100001];
pair <int,int> B[100001];
pair <ppair,int> Stick[100001];
int N, L;
long long D[2][100001], Ans;
void input(void)
{
int i, t, d, Acnt=0, Bcnt=0;
scanf("%d %d",&N,&L);
for(i=1 ; i<=N ; i++)
{
scanf("%d %d",&t,&d);
A[i]=make_pair(t,i);
B[i]=make_pair(d,i);
Stick[i].second=abs(t-d)+L;
}
sort(A+1,A+N+1);
sort(B+1,B+N+1);
A[0].first=B[0].first=-1;
for(i=1 ; i<=N ; i++)
{
if(A[i].first!=A[i-1].first)
Acnt++;
if(B[i].first!=B[i-1].first)
Bcnt++;
Stick[A[i].second].first.first=Acnt;
Stick[B[i].second].first.second=Bcnt;
}
sort(Stick+1,Stick+N+1);
}
void process(void)
{
int i;
long long temp;
for(i=1 ; i<=N ; i++)
{
temp=0;
if(D[0][Stick[i].first.first]<D[1][Stick[i].first.second]+Stick[i].second)
{
temp=D[1][Stick[i].first.second]+Stick[i].second;
if(Ans<temp)
Ans=temp;
}
if(D[1][Stick[i].first.second]<D[0][Stick[i].first.first]+Stick[i].second)
{
D[1][Stick[i].first.second]=D[0][Stick[i].first.first]+Stick[i].second;
if(Ans<D[1][Stick[i].first.second])
Ans=D[1][Stick[i].first.second];
}
if(temp)
D[0][Stick[i].first.first]=temp;
}
}
void output(void)
{
printf("%lld",Ans);
}
int main(void)
{
input();
process();
output();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
5388 KB |
Output is correct |
2 |
Correct |
0 ms |
5388 KB |
Output is correct |
3 |
Correct |
0 ms |
5388 KB |
Output is correct |
4 |
Correct |
0 ms |
5388 KB |
Output is correct |
5 |
Correct |
0 ms |
5388 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
28 ms |
5388 KB |
Output is correct |
2 |
Correct |
24 ms |
5388 KB |
Output is correct |
3 |
Correct |
64 ms |
5388 KB |
Output is correct |
4 |
Correct |
48 ms |
5388 KB |
Output is correct |
5 |
Correct |
56 ms |
5388 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
5388 KB |
Output is correct |
2 |
Correct |
0 ms |
5388 KB |
Output is correct |
3 |
Correct |
0 ms |
5388 KB |
Output is correct |
4 |
Correct |
0 ms |
5388 KB |
Output is correct |
5 |
Correct |
0 ms |
5388 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
5388 KB |
Output is correct |
2 |
Correct |
0 ms |
5388 KB |
Output is correct |
3 |
Correct |
0 ms |
5388 KB |
Output is correct |
4 |
Correct |
0 ms |
5388 KB |
Output is correct |
5 |
Correct |
0 ms |
5388 KB |
Output is correct |
6 |
Correct |
0 ms |
5388 KB |
Output is correct |
7 |
Correct |
0 ms |
5388 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
5388 KB |
Output is correct |
2 |
Correct |
4 ms |
5388 KB |
Output is correct |
3 |
Correct |
32 ms |
5388 KB |
Output is correct |
4 |
Correct |
64 ms |
5388 KB |
Output is correct |
5 |
Correct |
56 ms |
5388 KB |
Output is correct |
6 |
Correct |
60 ms |
5388 KB |
Output is correct |
7 |
Correct |
64 ms |
5388 KB |
Output is correct |
8 |
Correct |
60 ms |
5388 KB |
Output is correct |
9 |
Correct |
8 ms |
5388 KB |
Output is correct |
10 |
Correct |
8 ms |
5388 KB |
Output is correct |
11 |
Correct |
60 ms |
5388 KB |
Output is correct |
12 |
Correct |
64 ms |
5388 KB |
Output is correct |