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 ...
随机推荐
- 基于supersocket、C#对JT808协议进行解析构建gps监控平台服务端
GPS监控平台.车联网.物联网系统中GPRS网络数据的并发通讯和处理解析,主要功能有socket的UDP和TCP链路建立和维持,网络数据协议包接收与解析,分发上传到其他业务规则服务器,在物联网以及位置 ...
- maven手动导入jar包到本地仓库
一.cmd进入maven的bin目录下(我的目录是E:\cloud_cms\apache-maven-3.5.4\bin) cd E:\cloud_cms\apache-maven-3.5.4\bin ...
- 03_14_final关键字
03_14_final关键字 1. Final关键字 final的变量的值不能够被改变 final的成员变量 final的局部变量(形参) final的方法不能够被重写 final的类不能够被继承
- 01_14_Struts2_结果类型_result_type
01_14_Struts2_结果类型_result_type 1. result类型 result类型 说明 dispatcher 默认服务端转发jsp chain 服务端action转发 redir ...
- 学习笔记(七): Logistic Regression
目录 Calculating a Probability Model Training 1.Loss function for Logistic Regression 2.Regularization ...
- Linux NFS服务器的安装与配置详解
一.NFS服务简介 NFS是Network File System(网络文件系统).主要功能是通过网络让不同的服务器之间可以共享文件或者目录.NFS客户端一般是应用服务器(比如web,负载均衡等),可 ...
- 了解并使用springAOP(面向切面编程)
Aop是干嘛的为什么要使用它 在业务系统中,总有一些散落,渗透到系统的各处且不得不处理的事情,这些穿插在既定业务中的操作就是所谓的“横切逻辑”,也称切面, 我们怎样才不受这些附加要求的干扰,专心于真正 ...
- Python 正则表达式 贪心匹配和非贪心匹配
Python的正则表达式默认是“贪心匹配”,即在有第二义的情况下,尽可能匹配最长的字符串,在正则表达式的花括号后面跟上问号,可以变为非贪心模式 >>> >>> ha ...
- (转)为什么在 2013 十月番中出现了很多以 3D 渲染代替传统 2D 绘画来表现人物的镜头?
一直都有的,特别是三次元这家公司一直致力于3d的风格化渲染既大家说的3d转2d.目前最厉害的商业化软件是pencil+,占领大部分的作品.而mentalray,早期用于disney的部分风格化渲染:i ...
- ZendFramework-2.4 源代码 - 整体架构(类图)