# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
20210 | myduddlf | 막대기 (KOI13_game) | C++98 | 96 ms | 19 KiB |
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 <stdio.h>
#include <math.h>
#include <algorithm>
using namespace std;
const int N=111111;
struct Stick{int t,d,s;};
int n,l;
Stick a[N];
int t_x[N],d_x[N];
long long e[N][2],v1,v2,ans;
int cmp(const Stick &p,const Stick &q){return p.t<q.t||(p.t==q.t&&p.d<q.d);}
int main()
{
int i,v;
scanf("%d%d",&n,&l);
for(i=0;i<n;++i)
{
scanf("%d%d",&a[i].t,&a[i].d);
a[i].s=abs(a[i].t-a[i].d)+l;
t_x[i]=a[i].t;
d_x[i]=a[i].d;
}
sort(t_x,t_x+n);
sort(d_x,d_x+n);
for(i=0;i<n;++i)
{
a[i].t=lower_bound(t_x,t_x+n,a[i].t)-t_x;
a[i].d=lower_bound(d_x,d_x+n,a[i].d)-d_x;
}
sort(a,a+n,cmp);
for(i=0;i<n;++i)
{
v1=e[a[i].t][0]+a[i].s;
v2=e[a[i].d][1]+a[i].s;
if(v1>e[a[i].d][1]) e[a[i].d][1]=v1;
if(v2>e[a[i].t][0]) e[a[i].t][0]=v2;
if(v1>ans) ans=v1;
if(v2>ans) ans=v2;
}
printf("%lld\n",ans);
return 0;
}
Compilation message (stderr)
# | 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... |