#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;
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;
}
Compilation message
/usr/bin/ld: /tmp/ccLu7S3x.o: in function `main':
grader.c:(.text.startup+0x1ef): undefined reference to `delivery(int, int, int, int*)'
collect2: error: ld returned 1 exit status