Submission #219802

#TimeUsernameProblemLanguageResultExecution timeMemory
219802NightlightBoxes with souvenirs (IOI15_boxes)C++14
0 / 100
5 ms384 KiB
#include "boxes.h"
#include <bits/stdc++.h>
using namespace std;

long long dpL[10000005], dpR[10000005];

long long delivery(int N, int K, int L, int p[]) {
  for(int i = 1; i <= N; i++) {
    dpL[i] = p[i - 1] * 2LL;
    if(i > K) dpL[i] += dpL[i - K];
  }
  for(int i = N; i > 0; i--) {
    dpR[i] = (L - p[i - 1]) * 2LL;
    if(i + K <= N) dpR[i] += dpR[i + K]; 
  }
  long long ans = 1e18;
  for(int i = 0; i <= N; i++) {
    ans = min(ans, dpL[i] + dpR[i + 1]);
  }
  for(long long l = 1, r = K; r <= N; l++, r++) {
    ans = min(ans, dpL[l - 1] + dpR[r + 1] + K);
  }
  return ans;
}
#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...