# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
412930 | ScarletS | Boxes with souvenirs (IOI15_boxes) | C++17 | 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 ll long long
using namespace std;
const int INF = 2e9+7;
ll delivery(int n, int k, int l, int p[])
{
int x=0,y=n-1;
ll ans=0;
for (int i=k-1;i<n;i+=k)
{
if (p[i]>(l-1)/2)
break;
x=i+1;
ans+=p[i]*2;
//cout<<p[i]*2<<"!\n";
}
for (int i=n-k;i>=0;i-=k)
{
if (p[i]<(l+2)/2)
break;
y=i-1;
ans+=(l-p[i])*2;
//cout<<(l-p[i])*2<<"!\n";
}
//cout<<x<<" "<<y<<"\n";
ans+=1LL*((y-x+k)/k)*l;
return ans;
}
int main()
{
int n,k,l;
cin>>n>>k>>l;
int p[n];
for (int i=0;i<n;++i)
cin>>p[i];
cout<<delivery(n,k,l,p);
}