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
std::vector<int> people;
int n, l, k;
int dist(int curr)
{
return std::min(l - people[curr], people[curr]);
}
int dp[1000][1000];
long long f(int curr, int pres) //pres + 1 gifts left at person curr
{
if (dp[curr][pres])
return dp[curr][pres];
if (curr == n)
return dp[curr][pres] = dist(curr);
long long optionA = pres ? std::abs(people[curr] - people[curr+1]) + f(curr + 1, pres - 1) : INF;
long long optionB = dist(curr) + dist(curr + 1) + f(curr + 1, k-1);
return dp[curr][pres] = std::min(optionA, optionB);
}
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());
return f(0, K - 1);
}
Compilation message (stderr)
boxes.cpp: In function 'long long int f(int, int)':
boxes.cpp:26:37: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
26 | return dp[curr][pres] = std::min(optionA, optionB);
| ~~~~~~~~^~~~~~~~~~~~~~~~~~
# | 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... |