| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1349801 | pmh | Boxes with souvenirs (IOI15_boxes) | C++20 | 0 ms | 0 KiB |
#include "boxes.h"
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fr(i, a, b) for(int i = a; i <= b; i++)
#define frd(i, a, b) for(int i = a; i >= b; i--)
const int N = 1e7 + 5;
int cw[N], ccw[N], a[N];
long long delivery(int n, int k, int l, int pos[]) {
fr(i, 1, n) a[i] = pos[i - 1];
fr(i, 1, n) cw[i] = cw[max(0, i - k)] + a[i]*2;
frd(i, n, 1) ccw[i] = ccw[min(n + 1, i + k)] + 2*(l - a[i]);
ll ans = 1e18;
fr(i, 0, n) {
mini(ans, cw[i] + ccw[i + 1]);
mini(ans, cw[i] + ccw[min(n + 1, i + k + 1)] + l);
}
return ans;
}