codechef May Challenge 2016 FORESTGA: Forest Gathering 二分
Description
All submissions for this problem are available.
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
Chef is the head of commercial logging industry that recently bought a farm containing N trees. You are given initial height of the i-th tree by Hi and the rate of growth of height as Ri meters per month. For simplicity, you can assume that all the trees are perfect cylinders of equal radius. This allows us to consider only the height of trees when we talk about the amount of wood.
In Chef's country, laws don't allow one to cut a tree partially, so one has to cut the tree completely for gathering wood. Also, laws prohibit cutting trees of heights (strictly) lower than L meters.
Today Chef received an order of W meters (of height) of wood. Chef wants to deliver this order as soon as possible. Find out how minimum number of months he should wait after which he will able to fulfill the order. You can assume that Chef's company's sawing machines are very efficient and take negligible amount of time to cut the trees.
Input
There is a single test case per test file.
The first line of the input contains three space separated integers N, W and L denoting the number of trees in the farm, the amount of wood (in meters) that have to be gathered and the minimum allowed height of the tree to cut.
Each of next N lines contain two space separated integers denoting Hi and Ri respectively.
Output
Output a single integer denoting the number of months that have to pass before Chef will be able to fulfill the order.
Constraints
- 1 ≤ N ≤ 105
- 1 ≤ W, L ≤ 1018
- 1 ≤ Hi, Ri ≤ 109
Subtasks
- Subtask #1 [40 points]: 1 ≤ N, W, L ≤ 104
- Subtask #2 [60 points]: No additional constraints
Example
Input:
3 74 51
2 2
5 7
2 9 Output:
7
Explanation
After 6 months, heights of each tree will be 14, 47 and 56 respectively. Chef is allowed to cut only the third tree, sadly it is not enough to fulfill an order of 74 meters of wood.
After 7 months, heights of each tree will be 16, 54 and 65 respectively. Now Chef is allowed to cut second and third trees. Cutting both of them would provide him 119 meters of wood, which is enough to fulfill the order.
Input
Output
Sample Input
Sample Output
Hint
Languages: ADA, ASM, BASH, BF, C, C99 strict, CAML, CLOJ, CLPS, CPP 4.3.2, CPP 4.9.2, CPP14, CS2, D, ERL, FORT, FS, GO, HASK, ICK, ICON, JAVA, JS, LISP clisp, LISP sbcl, LUA, NEM, NICE, NODEJS, PAS fpc, PAS gpc, PERL, PERL6, PHP, PIKE, PRLG, PYPY, PYTH, PYTH 3.1.2, RUBY, SCALA, SCM chicken, SCM guile, SCM qobi, ST, TCL, TEXT, WSPC
#include<iostream>
#include<cstring>
#include<cstdio>
#define ll long long
using namespace std;
ll n,w,l;
struct node
{
ll h,r;
}N[];
bool check(ll exm)
{
ll sum=;
if(exm==)
{
for(int i=;i<=n;i++)
{
if(N[i].h>=l)
sum+=N[i].h;
if(sum>=w)
{
return true;
}
}
return false;
}
for(int i=;i<=n;i++)
{
if((N[i].r>(l-N[i].h)/exm)||(N[i].r==(l-N[i].h)/exm&&(l-N[i].h)%exm==))//*********
{
sum=sum+N[i].h;
ll cha=w-sum;
if(sum>=w)
{
return true;
}
if(cha/N[i].r<=exm)
{
return true;
}
sum=sum+exm*N[i].r;
}
}
return false;
}
int main()
{
while(scanf("%I64d %I64d %I64d",&n,&w,&l)!=EOF)
{
memset(N,,sizeof(N));
for(int i=;i<=n;i++)
scanf("%I64d %I64d",&N[i].h,&N[i].r);
ll l=;
ll r=w;
ll mid;
while(l<r)
{
mid=(l+r)>>;
if(check(mid))
r=mid;
else
l=mid+;
}
cout<<l<<endl;
}
return ;
}
codechef May Challenge 2016 FORESTGA: Forest Gathering 二分的更多相关文章
- CodeChef Forest Gathering —— 二分
题目链接:https://vjudge.net/problem/CodeChef-FORESTGA 题解: 现场赛.拿到这题很快就知道是二分,但是一直wa,怎么修改也wa,后来又换了种错误的思路,最后 ...
- codechef May Challenge 2016 LADDU: Ladd 模拟
All submissions for this problem are available. Read problems statements in Mandarin Chinese, Russia ...
- codechef May Challenge 2016 CHSC: Che and ig Soccer dfs处理
Description All submissions for this problem are available. Read problems statements in Mandarin Chi ...
- Codechef April Challenge 2019 游记
Codechef April Challenge 2019 游记 Subtree Removal 题目大意: 一棵\(n(n\le10^5)\)个结点的有根树,每个结点有一个权值\(w_i(|w_i\ ...
- Codechef October Challenge 2018 游记
Codechef October Challenge 2018 游记 CHSERVE - Chef and Serves 题目大意: 乒乓球比赛中,双方每累计得两分就会交换一次发球权. 不过,大厨和小 ...
- Codechef September Challenge 2018 游记
Codechef September Challenge 2018 游记 Magician versus Chef 题目大意: 有一排\(n(n\le10^5)\)个格子,一开始硬币在第\(x\)个格 ...
- codechef February Challenge 2018 简要题解
比赛链接:https://www.codechef.com/FEB18,题面和提交记录是公开的,这里就不再贴了 Chef And His Characters 模拟题 Chef And The Pat ...
- BZOJ 2016: [Usaco2010]Chocolate Eating( 二分答案 )
因为没注意到long long 就 TLE 了... 二分一下答案就Ok了.. ------------------------------------------------------------ ...
- codechef January Challenge 2017 简要题解
https://www.codechef.com/JAN17 Cats and Dogs 签到题 #include<cstdio> int min(int a,int b){return ...
随机推荐
- android studio 安装以及遇到的一些问题
1 安装 jkd ,版本一般是最新的,下怎么样的看一下自己电脑符合那种要求,可以去官网下 https://www.oracle.com/technetwork/java/javase/download ...
- CUDA中记录执行时间-GPU端
事件eventcudaEvent_t start,stop;cudaEventCreate(&start);cudaEventCreate(&stop);cudaEventRecord ...
- HttpServletRequest HttpServletResponse ServletException 重新打开后报红解决方法
tomcat安装路径下\lib\servlet-api.jar 复制到Dynamic Web Project 的 WEB-INF/lib下,刷新
- C的xml编程-libxml2
这里主要讲述libxml2在linux下的使用. (以下内容除了linux下的安装步骤是自己写的,其余均出自http://www.blogjava.net/wxb_nudt/archive/2007/ ...
- UITableView 优化总结
最近在微博上看到一个很好的开源项目VVeboTableViewDemo,是关于如何优化UITableView的.加上正好最近也在优化项目中的类似朋友圈功能这块,思考了很多关于UITableView的优 ...
- JavaScript 交换两个变量的值
方法一 let a = "a", b = "b"; console.log(a, b); let t = a; a = b; b = t; console.lo ...
- Linux企业生产环境用户权限集中管理项目方案案例
企业生产环境用户权限集中管理项目方案案例: 1 问题现状 当前我们公司里服务器上百台,各个服务器上的管理人员很多(开发+运维+架构+DBA+产品+市场),在大家登录使用Linux服务器时,不同职能的员 ...
- 日期增加天数--JS Date
//日期加天数的方法 //dataStr日期字符串 //dayCount 要增加的天数 //return 增加n天后的日期字符串 function dateAddDays(dataStr,dayCou ...
- 第11课 文章分类(组件化开发) Thinkphp5商城第四季
目录 思路: 控制器里 扩展类里: 视图层: 思路: 控制器查出所有数据后调用扩展类里的无限级分类 public function catetree($cateRes) 方法. 把排序好的数据传给视图 ...
- pip3 的安装 同时安装lxml和pygame
ubuntu18.04中 首先查看自己电脑的python版本,一般都会有2, 和3 python -V python3 -V 查看pip版本 pip -V pip3 -V 现在我们就可以开始安装我们的 ...