#include "boxes.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef tuple <ll,ll,ll> plll;
typedef vector <plll> vplll;
typedef pair <ll,ll> pll;
typedef vector <ll> vll;
typedef vector <pll> vpll;
typedef vector <vector <pll>> vvpll;
typedef vector <vector <ll>> vvll;
typedef vector <bool> vb;
typedef vector <vector <bool>> vvb;
#define loop(i, s, e) for (ll i = (s); i < (e); ++i)
#define loopr(i, e, s) for (ll i = (e)-1; i >= (s); --i)
#define all(a) a.begin(), a.end()
const ll inf = 1e9 + 7;
ll n,k,l;
vll p;
long long delivery(int N, int K, int L, int P[]) {
n=N,k=K,l=L;
p.resize(n);
loop(i,0,n) p[i] = P[i];
if (n==1) {
return min(l, p[0] + min(p[0],l-p[0]));
}
sort(all(p));
p.push_back(p[0]);
ll mx = 0;
ll maxi = *max_element(all(p));
pll d = {-1,-1};
loop(i,0,n) {
ll a = p[i], b = p[i+1];
if (abs(a-b) > mx) {
mx = abs(a-b);
d.first = a, d.second = b;
}
}
ll ans = min({l,(d.first + d.second)*2, (maxi + min(maxi, l-maxi)) });
return ans;
}
# | 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... |