记录编号 278729 评测结果 AAAAAAAAAA
题目名称 砍树 最终得分 100
用户昵称 GravatarDream 是否通过 通过
代码语言 C++ 运行时间 0.636 s
提交时间 2016-07-08 15:07:28 内存使用 7.94 MiB
显示代码纯文本
#include <cstdio>
#include <iostream>
#include <cmath>
#include <vector>
#include <cstdlib>
#include <algorithm>
#define MAX(a,b)(a>b?a:b)
using namespace std;
typedef long long ll;
ll n,m;
ll maxx=0;
ll A[1000001]={0};
void read(){
	freopen("eko.in","r",stdin);
	freopen("eko.out","w",stdout);
}

inline ll Dread(){
	ll data=0;
	char ch=getchar();
	while(ch>'9'||ch<'0') ch=getchar();
	do{
		data=data*10+ch-'0';
		ch=getchar();
	}while(ch<='9'&&ch>='0');
	return data;
}

void Debug(){
	ll i=n;
	ll sum=0;
	while(A[i]>114)
		sum=A[i--]+sum;
	i++;
	printf("%ld\n",sum);
	printf("%ld\n",i);
}


void Init(){
	scanf("%ld",&n);
	scanf("%ld",&m);
	//m=Dread();
	for(ll i=1;i<=n;i++){
		scanf("%ld",&A[i]);
		maxx=MAX(maxx,A[i]);
	}
	sort(A+1,A+n+1);
	
	return;
}

int judge(ll high){
	ll tmp=0;
	for(ll i=n;i>=1;i--){
		if(A[i]>high) tmp+=(A[i]-high);
		else break;
	}
	if(tmp>m) return -1;//high is too low
	if(tmp==m) return 0;
	if(tmp<m) return 1;//high is too high
}


int main(){
	read();
	Init();
	//Debug();
	ll l=0,r=maxx+1;
	ll mid;
	while(l<=r){
		mid=(l+r)>>1;
		int ok=judge(mid);
		if(ok==-1||ok==0) l=mid+1;
		if(ok==1) r=mid-1;
		//if(ok==0){printf("%ld",mid) ; break;}
	}
	printf("%ld",r);		
	return 0;
}