#include <bits/stdc++.h>
#include "boxes.h"
using namespace std;
long long n, k, l, m, cnt, t, a, lft[10000], ans, x, y, v, ans1, rt[10000], curr;
long long delivery(int N, int K, int L, int p[]) {
N = n;
K = k;
L = l;
for (int i = 0; i < n; i++) {
if (p[i] <= l-p[i]) lft[a] = p[i], a++;
else rt[v] = l-a[i], v++;
}
t = a-k+1;
ans = 1e18;
for (int i = 0; i < k; i++) {
curr = ans;
ans = 0;
x = t+i;
y = t+i+k;
if (t < 0) t = 0;
for (int j = 0; j < x; j++) {
cnt++;
if (cnt%k == 0) ans += 2*p[j], cnt = 0;
}
if (cnt) ans += 2*p[x-1], cnt = 0;
for (int j = t+i+k; j < n; j++) {
cnt++;
if (cnt%k == 0) ans += (l-p[j-k+1])*2, cnt = 0;
}
if (cnt) ans += 2*(l - p[n-cnt%k]), cnt = 0;
ans = min(ans, curr);
}
ans += l;
for (int i = 0; i < a; i++) {
cnt++;
if (cnt%k == 0) ans1 += lft[i], cnt = 0;
}
if (cnt) ans1 += 2*lft[a-1], cnt = 0;
sort(rt,rt+v);
for (int i = 0; i < v; i++) {
cnt++;
if (cnt%k == 0) ans1 += rt[i], cnt = 0;
}
if (cnt) ans1 += 2*rt[v-1], cnt = 0;
return min(2*ans1,ans);
}
Compilation message
boxes.cpp: In function 'long long int delivery(int, int, int, int*)':
boxes.cpp:6:6: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
N = n;
^
boxes.cpp:7:6: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
K = k;
^
boxes.cpp:8:6: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
L = l;
^
boxes.cpp:11:21: error: invalid types 'long long int[int]' for array subscript
else rt[v] = l-a[i], v++;
^
boxes.cpp:26:19: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
for (int j = t+i+k; j < n; j++) {
~~~^~