Boj16564_히오스 프로게이머

Published: by Creative Commons Licence

boj 16564_히오스 프로게이머

#include<iostream>
#include<algorithm>
using namespace std;
int arr[1000001];
int n, k;

int go(int l, int r) {
	if (l > r) return r;
	long long mid = (long long)(l + r) / 2, sum = 0;
	for (int i = 0; i < n; i++)  
		if(mid>arr[i]) 
			sum += (mid - arr[i]); 
	if (sum > k) return go(l, mid - 1);//r = mid - 1;
	else return go(mid + 1, r);//l = mid + 1;
}

int main() {
	scanf("%d %d", &n, &k);
	for (int i = 0; i < n; i++) {
		scanf("%d", &arr[i]);
	}
	cout<<go(0, 2000000005);
}