제출 #13485

#제출 시각아이디문제언어결과실행 시간메모리
13485ainta쌀 창고 (IOI11_ricehub)C++98
100 / 100
23 ms4988 KiB
#include "ricehub.h"

int besthub(int R, int L, int X[], long long B)
{
	int i, be, ed, t, Res = 0;
	long long S = 0;
	for (i = 0; i < R; i++){
		if (i == 0)be = 0, ed = 0, S = 0;
		if (ed < i)be = ed = i, S = 0;
		t = i * 2 - ed - 2;
		if (be == t){
			S -= (X[i] - X[be]);
			be++;
		}
		t = i * 2 - ed - 1;
		if (be == t){
			S -= (X[i] - X[be]);
			be++;
		}
		while (be - 1 >= 0 && ed + 1 < R){
			if (S + X[ed + 1] - X[be - 1] > B)break;
			S += X[ed + 1] - X[be - 1];
			be--, ed++;
		}
		if (ed + 1 < R && S + X[ed + 1] - X[i]<= B){
			S += X[ed + 1] - X[i];
			ed++;
		}
		if (Res < ed - be + 1)Res = ed - be + 1;
		if (i != R - 1 && be + ed == i * 2){
			S += X[i + 1] - X[i];
		}
	}
	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...