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 "boxes.h"
#include <vector>
#include <algorithm>
#include <map>
#include <iostream>
#define INF 1'000'000'000'000'000'000
std::vector<long long> people;
long long n, l, k;
long long dist(long long curr)
{
return std::min(l - people[curr], people[curr]);
}
long long dp[1005];
long long delivery(int N, int K, int L, int p[])
{
n = N, k = K, l = L;
people.push_back(0);
for (int i = 0; i < N; ++i)
people.push_back(p[i]);
std::sort(people.begin(), people.end());
for (int j = K-1; j >= 0; --j)
dp[j] = dist(N);
for (int i = N-1; i >= 0; --i)
{
long long var = dp[K-1];
for (int j = K-1; j >= 0; --j)
{
long long optionA = j ? std::abs(people[i] - people[i + 1]) + dp[j-1] : INF;
long long optionB = dist(i) + dist(i+1) + var;
dp[j] = std::min(optionA, optionB);
}
}
return dp[K - 1];
}
# | 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... |