博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
spoj11814
阅读量:4687 次
发布时间:2019-06-09

本文共 2666 字,大约阅读时间需要 8 分钟。

EKO - Eko

 

Lumberjack Mirko needs to chop down M metres of wood. It is an easy job for him since he has a nifty new woodcutting machine that can take down forests like wildfire. However, Mirko is only allowed to cut a single row of trees.

Mirko‟s machine works as follows: Mirko sets a height parameter H (in metres), and the machine raises a giant sawblade to that height and cuts off all tree parts higher than H (of course, trees not higher than H meters remain intact). Mirko then takes the parts that were cut off. For example, if the tree row contains trees with heights of 20, 15, 10, and 17 metres, and Mirko raises his sawblade to 15 metres, the remaining tree heights after cutting will be 15, 15, 10, and 15 metres, respectively, while Mirko will take 5 metres off the first tree and 2 metres off the fourth tree (7 metres of wood in total).

Mirko is ecologically minded, so he doesn‟t want to cut off more wood than necessary. That‟s why he wants to set his sawblade as high as possible. Help Mirko find the maximum integer height of the sawblade that still allows him to cut off at least M metres of wood.

Input

The first line of input contains two space-separated positive integers, N (the number of trees, 1 ≤ N ≤ 1 000 000) and M(Mirko‟s required wood amount, 1 ≤ M ≤ 2 000 000 000).

The second line of input contains N space-separated positive integers less than 1 000 000 000, the heights of each tree (in metres). The sum of all heights will exceed M, thus Mirko will always be able to obtain the required amount of wood.

Output

The first and only line of output must contain the required height setting.

Example

Input:4 720 15 10 17Output:15
Input:5 204 42 40 26 46Output:36
#include 
using namespace std; int main() { long long int N, i, M; scanf( "%lld%lld", &N, &M ); int array[ N ]; long long int max = 0, h = 0; long long int beg, end, mid; long long int cutted; for ( i = 0; i < N; ++i ) { scanf( "%d", array + i ); if ( array[ i ] > max ) { max = array[ i ]; } } beg = 0; end = max; while ( beg <= end ) { mid = ( beg + end ) / 2; cutted = 0; for ( i = 0; i < N; ++i ) { if ( array[ i ] - mid > 0 ) { cutted += array[ i ] - mid; } } if ( cutted > M ) { beg = mid + 1; if ( mid > h ) { h = mid; } } else if ( cutted < M ) { end = mid - 1; } else { h = mid; break; } } printf( "%lld\n", h ); return 0;}

  

转载于:https://www.cnblogs.com/passion-sky/p/8997596.html

你可能感兴趣的文章
开源 视频会议 收藏
查看>>
核心J2EE模式 - 截取过滤器
查看>>
test1
查看>>
.net开源CMS
查看>>
JdbcTemplate
查看>>
第一次使用maven记录
查看>>
SharePoint服务器端对象模型 之 使用CAML进展数据查询
查看>>
Building Tablet PC Applications ROB JARRETT
查看>>
Adobe® Reader®.插件开发
查看>>
【POJ 3461】Oulipo
查看>>
Alpha 冲刺 (5/10)
查看>>
使用Siege进行WEB压力测试
查看>>
斑马为什么有条纹?
查看>>
android多层树形结构列表学习笔记
查看>>
Android_去掉EditText控件周围橙色高亮区域
查看>>
《构建之法》第一、二、十六章阅读笔记
查看>>
Pandas基础(十一)时间序列
查看>>
arrow:让Python的日期与时间变的更好
查看>>
MySQL命令行参数
查看>>
MFC中 用Static控件做超链接(可以实现变手形、下划线、字体变色等功能)
查看>>