# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
67702 | theknife2001 | 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 "boxes.h"
#include "grader.cpp"
#include <bits/stdc++.h>
using namespace std;
const int N=1e6+55;
bool vis[N];
int n;
long long delivery(int N, int k, int L, int p[])
{
n=N;
int x;
int temp=0;
bool q=0;
long long ans=0;
for(int i=0;i<n;i++)
{
x=k;
temp=0;
while(x--&&i<n)
{
if(p[i]==0)
{
vis[i]=1;
i++;
x++;
}
if(p[i]-temp<=L-(p[i]-temp))
{
temp=p[i];
vis[i]=1;
i++;
}
else
break;
}
ans+=temp+min(temp,L-temp);
}
for(int i=n-1;i>=0&&vis[i]==0;i--)
{
x=k;
temp=0;
if(vis[i])
break;
while(x--&&!vis[i]&&i<n)
{
temp=p[i];
i--;
}
ans+=L-temp+min(temp,L-temp);
}
return ans;
}