#include "boxes.h"
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define pb push_back
#define all(x) (x).begin(), (x).end()
typedef long long ll;
using vi = vector<int>;
using vl = vector<ll>;
// probably binary search?
ll n, k, l;
vl p;
vl nxt, prev;
// ll sim_dist(ll p1, ll p2) {
// ll lmoves = 0, rmoves = 0;
// ll lpos = p1, rpos = p1;
// while (lpos != p2) {
// lpos--;
// if (lpos < 0) lpos = l - 1;
// lmoves++;
// }
// while (rpos != p2) {
// rpos++;
// if (rpos >= l) rpos = 0;
// rmoves++;
// }
// return min(lmoves, rmoves);
// }
ll dist(ll p1, ll p2) {
if (p1 == p2) return 0;
if (p1 < p2) return dist(p2, p1);
else return min(p1 - p2, (l - p1) + p2);
}
ll delivery(int N, int K, int L, int P[]) {
n = N, k = K, l = L;
// cout << "N = " << n << "K = " << k << " L = " << L << "\n";
FOR(i, 0, n) p.pb(P[i]);
// FOR(i, 0, l) {
// FOR(j, 0, l) {
// ll d1 = dist(i, j);
// ll d2 = sim_dist(i, j);
// if (d1 != d2) {
// cout << "L = " << L << " i = " << i << " j = " << j << " dist = " << d1 << " simdist = " << d2 << "\n";
// }
// }
// }
// FOR(i, 0, n) {
// FOR(j, 0, n) {
// cout << "L = " << L << " Dist between " << i << " and " << j << " = " << dist(i, j) << "\n";
// }
// }
// return min(*max_element(all(p)) + dist(*max_element(all(p)), 0), l - *min_element(all(p)) + dist(*min_element(all(p)), 0));
ll max_pos = *max_element(all(p));
ll min_pos = *min_element(all(p));
ll min_dist = dist(min_pos, l);
return min({l, 2LL * max_pos, 2LL * min_dist});
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |