# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
139996 | MrBrionix | 선물상자 (IOI15_boxes) | C++14 | 0 ms | 0 KiB |
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 <stdio.h>
#include <stdlib.h>
#include<bits/stdc++.h>
using namespace std;
long long pre[10000005],suf[20000005],sum,sol,n;
long long delivery(int N, int K, int L, int p[]) {
n=N;
sol=1000000000000000000ll;
for(int i=0;i<K;i++){
sum=0;
for(int j=i;j<N;j+=K){
sum+=p[j]*2ll;
pre[j]=sum;
}
}
for(int i=N-1;i>=N-K;i--){
sum=0;
for(int j=i;j>=0;j-=K){
sum+=(L-p[j])*2ll;
suf[j]=sum;
}
}
/*
for(int i=0;i<n;i++){
cout<<pre[i]<<" "<<suf[i]<<" con "<<i<<endl;
}*/
sol=l+suf[K+1];
for(int i=0;i<N;i++){
sol=min(sol,pre[i]+suf[i+1]);
sol=min(sol,L+pre[i]+suf[i+K+1]);
}
//cout<<sol<<endl;
return sol;
}
/*
static char _buffer[1024];
static int _currentChar = 0;
static int _charsNumber = 0;
static FILE *_inputFile, *_outputFile;
static inline int _read() {
if (_charsNumber < 0) {
exit(1);
}
if (!_charsNumber || _currentChar == _charsNumber) {
_charsNumber = (int)fread(_buffer, sizeof(_buffer[0]), sizeof(_buffer), _inputFile);
_currentChar = 0;
}
if (_charsNumber <= 0) {
return -1;
}
return _buffer[_currentChar++];
}
static inline int _readInt() {
int c, x, s;
c = _read();
while (c <= 32) c = _read();
x = 0;
s = 1;
if (c == '-') {
s = -1;
c = _read();
}
while (c > 32) {
x *= 10;
x += c - '0';
c = _read();
}
if (s < 0) x = -x;
return x;
}
int main() {
_inputFile = fopen("input.txt", "rb");
_outputFile = fopen("output.txt", "w");
int N, K, L, i;
N = _readInt();
K = _readInt();
L = _readInt();
int *p = (int*)malloc(sizeof(int) * (unsigned int)N);
for (i = 0; i < N; i++) {
p[i] = _readInt();
}
fprintf(_outputFile, "%lld\n", delivery(N, K, L, p));
return 0;
}*/