Submission #684163

#TimeUsernameProblemLanguageResultExecution timeMemory
684163sudheerays123쌀 창고 (IOI11_ricehub)C++17
68 / 100
240 ms1748 KiB
#include "ricehub.h"
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll int
const ll N = 100+5 , INF = 1e9 , MOD = 1e9+7;

int besthub(int R, int L, int X[], long long B){

	ll low = 1 , high = R;
	ll ans;

	function<bool(ll)> check = [&](ll l){

		for(ll i = 1; i <= R-l+1; i++){
			ll j = i+l-1;
			ll mid = (i+j)/2;

			ll cost = 0;
			for(ll k = i; k <= j; k++) cost += abs(X[k]-X[mid]);

			if(cost <= B) return true;
		}

		return false;
	};

	while(low <= high){
		ll mid = (low+high)/2;
		if(check(mid)){
			ans = mid;
			low = mid+1;
		}
		else high = mid-1;
	}

	return ans;
}

Compilation message (stderr)

ricehub.cpp: In function 'int besthub(int, int, int*, long long int)':
ricehub.cpp:37:9: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
   37 |  return ans;
      |         ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...