제출 #551235

#제출 시각아이디문제언어결과실행 시간메모리
551235alireza_kaviani쌀 창고 (IOI11_ricehub)C++17
100 / 100
31 ms2612 KiB
#include "ricehub.h"
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

const ll MAXN = 1e5 + 10;

ll n , k , A[MAXN] , ps[MAXN];

int check(ll x){
	ll l = x / 2 , r = x - l - 1;
	for(int i = 1 ; i + x <= n + 1 ; i++){
		ll cost = ps[i + x - 1] - ps[i + l] - ps[i + l - 1] + ps[i - 1] + A[i + l] * (l - r);
		if(cost <= k)	return 1;
	}
	return 0;
}

int besthub(int R, int L, int X[], long long B){
	n = R; k = B;
	for(int i = 1 ; i <= n ; i++){
		A[i] = X[i - 1];
		ps[i] = A[i] + ps[i - 1];
	}

	ll l = 1 , r = n + 1;
	while(r - l > 1){
		int mid = l + r >> 1;
		if(check(mid))	l = mid;
		else	r = mid;
	}
	return l;
}

컴파일 시 표준 에러 (stderr) 메시지

ricehub.cpp: In function 'int besthub(int, int, int*, long long int)':
ricehub.cpp:29:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   29 |   int mid = l + r >> 1;
      |             ~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...