比赛 20160707 评测结果 AAAAAAAAAA
题目名称 砍树 最终得分 100
用户昵称 Riolu 运行时间 0.560 s
代码语言 C++ 内存使用 7.94 MiB
提交时间 2016-07-07 16:08:46
显示代码纯文本
/*=========================================*
 * Auther: Riolu
 * PID:2374
 * Time: 2016.7.7
 * Copyright 2016 Riolu. All Rights Reserved.
 *=========================================*/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#define ll long long
#define N 1000000
#include<ctime>
using namespace std;
/*=========DEFINE============================*/
ll n,m,maxn;
ll len[N];
/*==========================================*/
int judge(ll h){
	ll i,sum=0;
	for(i=1;i<=n;i++)if(len[i]>h)sum=sum+len[i]-h;
	if(sum>=m)return 1;
		return 0;
	}
/*==========================================*/
void read(){
	freopen("eko.in","r",stdin);
	freopen("eko.out","w",stdout);
	}
/*=========MAIN==============================*/
int main(){
	read();
	cin>>n>>m;
	ll i;
	for(i=1;i<=n;i++){
		scanf("%lld",&len[i]);
		if(len[i]>maxn)maxn=len[i];
		}
	ll l=0,r=maxn+1;
	while(l+1<r){
		ll mid=(l+r)>>1;
		if(judge(mid))l=mid;
			else r=mid;
		}
		cout<<l<<endl;
		//cout<<clock()<<endl;
	return 0;
	}