This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include <boxes.h>
using namespace std;
typedef vector<int> vi;
typedef vector<pair<int, int> > vpii;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef vector<ll> vll;
#define INF 1000000000000000000LL
#define MOD 1000000007LL
#define EPSILON 0.00001
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define FOR(i, a, b) for (int i=(a); i<=(signed)(b); i++)
#define F0R(i, a) for (int i=0; i<(signed)(a); i++)
#define RFOR(i, a, b) for (int i=(a); i >= b; i--)
#define MN 10000005
int n, k; ll l;
ll d[MN];
ll ps[MN];
ll rps[MN];
ll delivery(int N, int K, int L, int positions[]){
n = N; k = K; l = (ll)L;
F0R(i, n) d[i] = positions[i];
F0R(i, n){
ps[i] = d[i]*2;
if(i >= k){
ps[i] += ps[i-k];
}
}
RFOR(i, n-1, 0){
rps[i] = (l-d[i])*2;
if(i+k < n){
rps[i] += rps[i+k];
}
}
ll ans = INF;
F0R(i, n-1){
ans = min(ans, ps[i]+rps[i+1]);
}
ans = min(ans, min(rps[0], ps[n-1]));
if(k >= n) ans = min(ans, l);
else{
F0R(i, n-k+1){
int lf = i-1, rt = i+k;
ll res = l+(lf<0?0:ps[lf])+(rt>=n?0:rps[rt]);
ans = min(ans, res);
}
}
return ans;
}
/*int main(){
//ios_base::sync_with_stdio(false);
//cin.tie(0);
int N, K, L;
cin >> N >> K >> L;
int pos[N];
F0R(i, N) cin >> pos[i];
cout << delivery(N, K, L, pos) << "\n";
return 0;
}*/
# | 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... |