# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
434877 | jeqcho | 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 <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pair<int,int>> vpi;
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)
#define pb push_back
#define rsz resize
#define sz(x) int(x.size())
#define all(x) begin(x), end(x)
#define fi first
#define se second
int const N=1e7+3;
vector<ll> p;
int n,k;
ll delivery(int n1, int K, ll L, int p1[]) {
k=K;
n=n1;
p.rsz(n);
ll L=L1;
F0R(i,n)p[i]=p1[i];
ll cur=0;
int i=0;
int j=n-1;
ll ans=0;
int cnt=k;
while(i<=j)
{
if(cnt==0)
{
ans += min(cur,L-cur);
cur=0;
cnt=k;
}
ll dcw=p[i]-cur;
if(dcw<0)dcw = L-cur+p[i];
ll dccw=cur-p[j];
if(dccw<0)dccw=cur+L-p[j];
if(dcw<dccw)
{
ans+=dcw;
cur=p[i];
++i;
}
else
{
ans+=dccw;
cur=p[j];
--j;
}
--cnt;
}
ans+=min(L-cur,cur);
return ans;
}