이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "boxes.h"
#include <bits/stdc++.h>
#define SZ(v) ((int)(v).size())
using namespace std;
using ll = long long;
ll delivery(int N, int K, int L, int p[])
{
ll sol(1e18);
vector<ll> increasing(N), decreasing(N);
for (int i(0); i < N; ++i)
increasing[i] = decreasing[i] = p[i];
sort(increasing.begin(), increasing.end());
sort(decreasing.rbegin(), decreasing.rend());
vector<ll> getInc(N), getDec(N);
for (int i(0); i < N; ++i)
{
getInc[i] = 2 * increasing[i];
getDec[i] = 2 * (L - decreasing[i]);
if (i >= K)
{
getInc[i] += getInc[i-K];
getDec[i] += getDec[i-K];
}
}
for (int takeInc(0); takeInc <= N; ++takeInc)
{
ll cost(0);
if (takeInc)
cost += getInc[takeInc-1];
if (takeInc < N)
cost += getDec[N - takeInc-1];
sol = min(sol, cost);
}
for (int takeInc(0); takeInc < N; ++takeInc)
{
ll cost(0);
if (takeInc)
cost += getInc[takeInc-1];
cost += L;
if (takeInc + K < N)
cost += getDec[N - takeInc - K - 1];
sol = min(sol, cost);
}
return sol;
}
# | 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... |