# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
134550 | 20160161simone | Boxes with souvenirs (IOI15_boxes) | C++14 | 0 ms | 0 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 <bits/stdc++.h>
#define M 10000010
#define inf 0x3f3f3f
using namespace std;
int mi[M],p[M],N,K,L;
int main()
{
cin>>N>>K>>L;
for(int i=0;i<N;i++) cin>>p[i];
if(K==1)
{
long long ans=0;
for(int i=0;i<N;i++) ans+=min(abs(L-p[i]),abs(p[i]))*2;
//return ans;
}
if(K==N)
{
int Mli=p[0],Mlx=p[0],Mri=p[N-1],Mrx=p[N-1];
for (int i=0;i<N;i++)
{
if(p[i]*2<L) Mlx=p[i];
if(p[i]*2==L) return L;
if(p[i]*2>L)
{
Mri=p[i];
break;
}
}
if(Mli*2>L)
{
return (L-Mli)*2;
}
else
if(Mrx*2<L)
{
return Mrx*2;
}
else
{
if (L<Mlx*2+(L-Mri)*2) return L;
else return Mlx*2+(L-Mri)*2;
}
}
}