Submission #588384

#TimeUsernameProblemLanguageResultExecution timeMemory
588384lorenzoferrariBoxes with souvenirs (IOI15_boxes)C++17
10 / 100
412 ms8180 KiB
#include "boxes.h"
#include <bits/stdc++.h>
using namespace std;
using LL = long long;

const LL INF = 1e18;

LL solve(int n, int k, int l, vector<int> p) {
  sort(p.begin(), p.end());
  vector<vector<LL>> dp(n+1, vector<LL>(n+1, INF));
  dp[0][0] = 0;
  for (int a = 0; a <= n; ++a) {
    for (int b = 0; a + b <= n; ++b) {
      for (int s = 1; s <= k && s <= a; ++s) {
        dp[a][b] = min(dp[a][b], dp[a - s][b] + p[a - 1]);
      }
      for (int s = 1; s <= k && s <= b; ++s) {
        dp[a][b] = min(dp[a][b], dp[a][b - s] + l - p[n - b]);
      }
    }
  }
  LL ans = INF;
  for (int i = 0; i <= n; ++i) {
    ans = min(ans, dp[i][n - i]);
  }
  return 2 * ans;
}

LL delivery(int n, int k, int l, int p[]) {
  vector<int> v; // those you don't take greedily
  for (int i = 0; i < n; ++i) {
    v.push_back(p[i]);
  }
  return solve(n, k, l, v);
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...