# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
990081 | haiphong5g0 | 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>
#include "boxes.h"
#define task "CAU5"
#define pl pair<ll, ll>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i, a, b, c) for (ll i=a; i<=b; i+=c)
#define FORE(i, a, b, c) for (ll i=a; i>=b; i+=c)
using namespace std;
using ll = long long;
using ull = unsigned long long;
const ll Mod = 998244353;
const int maxn = 1e7+1;
const ll Inf = 1e10;
ll ans=0, n, k, l, A[maxn];
inline ll dis(ll a, ll l)
{
return min(a, l-a);
}
ll delivery(ll n, ll k, ll l, ll A[])
{
ll a = -1, b = n, ans = 0;
if (n % k != 0) {
ans += min(dis(A[a+n%k],l), dis(A[b-n%k],l)) + dis(min(dis(A[a+n%k],l), dis(A[b-n%k],l)),l);
if (dis(A[a+n%k],l) <= dis(A[b-n%k],l)) a += n%k;
else b -= n%k;
}
while (a + 1 != b) {
if (b - a == k + 1) {
if (A[b-1] <= l/2) ans += (l/2)*2;
else ans += l;
break;
}
else {
ans += min(dis(A[a+k],l), dis(A[b-k],l)) + dis(min(dis(A[a+k],l), dis(A[b-k],l)),l);
if (dis(A[a+k],l) <= dis(A[b-k],l)) a+=k;
else b-=k;
}
}
return ans;
}