제출 #762313

#제출 시각아이디문제언어결과실행 시간메모리
762313ZeroCool선물상자 (IOI15_boxes)C++14
100 / 100
754 ms264760 KiB
#include "boxes.h"
#include <bits/stdc++.h>
#define ll long long
#define inf 1e18

using namespace std;

ll delivery(int n, int k, int l, int arr[]) {
    
    long long prefix[n+5];
    long long suffix[n+5];
    memset(prefix,0,sizeof(prefix));
    memset(suffix,0,sizeof(suffix));
    
    for(int x=1;x<=n;x++){
		prefix[x]=prefix[max(0,x-k)]+2*arr[x-1];
	}
	
	for(int x=n;x>=1;x--){
		suffix[x]=suffix[min(n+1,x+k)]+2*(l-arr[x-1]);
	}
	
	long long best=LONG_LONG_MAX;
	
	for(int x=0;x<=n;x++){
		best=min(best,prefix[x]+suffix[x+1]);
	}
	
	for(int x=0;x<=n-k;x++){
		best=min(best,prefix[x]+suffix[x+k+1]+l);
	}
	return best;
    
}
#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...