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[])
{
int now = 0;
int stock = k;
ll ans = 0;
while(true)
{
if(now == 0)
{
stock = k;
}
if(stock == 0)
{
ans+=min(now, l-now);
now = 0;
stock = k;
}
int dist = 2*MX, nod = -1, idx = -1;
for(int i = 0; i < n; i++)
{
if(a[i] != -1)
{
if(min(max(now, a[i])-min(now, a[i]), l-max(now, a[i])+min(now, a[i])) < dist)
{
nod = a[i];
idx = i;
dist = min(max(now, a[i])-min(now, a[i]), l-max(now, a[i])+min(now, a[i]));
}
}
}
if(nod == -1)
{
ans+=min(now, l-now);
break;
}
a[idx] = -1;
ans+=dist;
stock--;
if(max(now, nod)-min(now, nod) >= l-max(now, nod)+min(now, nod))
{
stock = k-1;
}
now = nod;
}
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;
}
*/
/*
5 1 8
0 0 1 2 5
*/
# | 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... |