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>
#define ll long long
#define fi first
#define se second
#define sz(x) (int)x.size()
#define ALL(v) v.begin(),v.end()
#define MASK(k) (1LL << (k))
#define BIT(x, i) (((x) >> (i)) & 1)
#define oo (ll)1e18
#define INF (ll)1e9
#define MOD (ll)(1e9 + 7)
#include "boxes.h"
using namespace std;
template<class T1, class T2>
bool maximize(T1 &a, T2 b){if(a < b){a = b; return true;} return false;}
template<class T1, class T2>
bool minimize(T1 &a, T2 b){if(a > b){a = b; return true;} return false;}
template<class T1, class T2>
void add(T1 &a, T2 b){a += b; if(a >= MOD) a -= MOD;}
template<class T1, class T2>
void sub(T1 &a, T2 b){a -= b; if(a < 0) a += MOD;}
template<class T>
void cps(T &v){sort(ALL(v)); v.resize(unique(ALL(v)) - v.begin());}
const int lim = 1e7 + 10;
long long f[lim], g[lim];
long long delivery(int N, int K, int L, int positions[]){
int mid = (L + 1) / 2;
int n = N;
for(int i = 0; i < N; i++){
if(positions[i] > mid){
n = i;
break;
}
if(i + 1 >= K) f[i + 1] = f[i + 1 - K] + 2LL * positions[i];
else f[i + 1] = 2LL * positions[i];
}
for(int i = 0; i < N - n; i++){
if(i + 1 >= K) g[i + 1] = g[i + 1 - K] + 2LL * (L - positions[N - i - 1]);
else g[i + 1] = 2LL * (L - positions[N - i - 1]);
}
long long ans = f[n] + g[N - n];
for(int i = 0; i <= n; i++) if(i + K > n){
minimize(ans, f[i] + g[max(0, N - i - K)] + L);
}
return ans;
}
// int main(){
// ios_base::sync_with_stdio(0); cin.tie(0);
// // freopen("ADVERT.inp","r",stdin);
// // freopen("ADVERT.out","w",stdout);
// cout << delivery(3, 2, 8, {1, 2, 5});
// 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... |