제출 #418751

#제출 시각아이디문제언어결과실행 시간메모리
418751nafis_shifatBoxes with souvenirs (IOI15_boxes)C++14
100 / 100
905 ms468908 KiB
#include "boxes.h"
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
using namespace std;
const int mxn=1e5+5;
const ll inf= 1e18;
ll delivery(int N, int K, int L, int p[]) {

	

	ll pre[2 * N + K] = {};


	deque<int> q;


	for(int i = 0; i < N; i++) {
		pre[i] = inf;
		if(i < K) pre[i] = min(L,2 * p[i]);

		while(!q.empty() && i - q.front() > K) q.pop_front();
		if(!q.empty()) {
			pre[i] = min(pre[i],pre[q.front()] + min(L,2 * p[i]));
		}

		while(!q.empty() && pre[q.back()] >= pre[i]) q.pop_back();
		q.push_back(i);
	}


	while(!q.empty()) q.pop_back();

	ll suf[2 * N + K] = {};

	for(int i = N - 1; i >= 0; i--) {
		suf[i] = inf;
		if(N - i <= K) suf[i] = min(L,2 * (L - p[i]));

		while(!q.empty() && q.front() - i > K) q.pop_front();
		if(!q.empty()) {
			suf[i] = min(suf[i],suf[q.front()] + min(L,2 *(L - p[i])));
		}

		while(!q.empty() && suf[q.back()] >= suf[i]) q.pop_back();
		q.push_back(i);




	}


	ll res = suf[0];

	for(int i = 0; i < N; i++) res = min(res,pre[i] + suf[i + 1]);

	if(N <= K) res = min(res, 1ll * L);



	return res;
}
#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...