제출 #90045

#제출 시각아이디문제언어결과실행 시간메모리
90045Retro3014선물상자 (IOI15_boxes)C++17
100 / 100
490 ms196092 KiB
#include "boxes.h"
#include <algorithm>

using namespace std;

#define MAX_N 10000000
typedef long long ll;

ll costf[MAX_N+1], coste[MAX_N+1];
ll answer;



long long delivery(int N, int K, int L, int p[]) {
	for(int i=0; i<N; i++){
		costf[i]=2*(ll)p[i]+(i<K?0:costf[i-K]);
	}	
	for(int i=N-1; i>=0; i--){
		coste[i]=(ll)(L-p[i])*2+(i>=N-K?0:coste[i+K]);
	}
	answer=min(costf[N-1], coste[0]);
	if(K>=N){
		answer=min(answer, (ll)L);
	}
	else{
		answer = min(answer, costf[N-K-1]+L);
		answer = min(answer, coste[K]+L);
	}
	for(int i=0; i<N-1; i++){
		answer=min(answer, costf[i]+coste[i+1]); 
		if(i+K+1<N){
			answer = min(answer, costf[i]+coste[i+K+1]+(ll)L);
		}
	}
    return answer;
}
#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...