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"
#define startt ios_base::sync_with_stdio(false);cin.tie(0);
typedef long long ll;
using namespace std;
#define vint vector<int>
#define all(v) v.begin(), v.end()
#define MOD 1000000007
#define MOD2 998244353
#define MX 1000000000
#define MXL 1000000000000000000
#define PI (ld)2*acos(0.0)
#define nax 200005
#define pb push_back
#define sc second
#define fr first
//#define int unsigned long long
//#define endl '\n'
#define ld long double
#define NO cout << "NO" << endl
#define YES cout << "YES" << endl
long long delivery(int n, int k, int l, int a[])
{
vector<ll> cw(n+2, MXL);
vector<ll> ccw(n+2, MXL);
sort(a, a+n);
cw[0] = 0;
for(int i = 1; i <= n; i++)
{
cw[i] = cw[max(0, i-k)] + 2*a[i-1];
}
ccw[n+1] = 0;
for(int i = n; i >= 1; i--)
{
ccw[i] = ccw[min(n+1, i+k)] + 2 * (l-a[i-1]);
}
ll ans = MXL;
for(int i = 0; i <= n; i++)
{
ans = min(ans, cw[i] + ccw[i+1]);
ans = min(ans, cw[i] + ccw[min(n+1, i+1+k)] + l);
}
return ans;
}
/*
int main()
{
int n, k, l;
cin >> n >> k >> l;
int a[n];
for(int i = 0; i < n; i++)
{
cin >> a[i];
}
cout << delivery(n, k, l, a) << endl;
}
*/
/*
3 2 8
1 2 5
4 3 8
1 3 4 6
*/
# | 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... |