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

  • 1N105
  • 1W, L1018
  • 1Hi, Ri109

Subtasks

  • Subtask #1 [40 points]: 1 ≤ N, W, L104
  • 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

Source Limit: 50000
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
 
题意:中文题面 https://s3.amazonaws.com/codechef_shared/download/translated/MAY16/mandarin/FORESTGA.pdf
题解:二分处理 二分月数 但是这里的check 需要特殊处理 直接计算相乘会爆LL
        技巧除法处理 注意代码中的*位置 除的时候要注意考虑细节问题
 
 #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 二分的更多相关文章

  1. CodeChef Forest Gathering —— 二分

    题目链接:https://vjudge.net/problem/CodeChef-FORESTGA 题解: 现场赛.拿到这题很快就知道是二分,但是一直wa,怎么修改也wa,后来又换了种错误的思路,最后 ...

  2. codechef May Challenge 2016 LADDU: Ladd 模拟

    All submissions for this problem are available. Read problems statements in Mandarin Chinese, Russia ...

  3. codechef May Challenge 2016 CHSC: Che and ig Soccer dfs处理

    Description All submissions for this problem are available. Read problems statements in Mandarin Chi ...

  4. Codechef April Challenge 2019 游记

    Codechef April Challenge 2019 游记 Subtree Removal 题目大意: 一棵\(n(n\le10^5)\)个结点的有根树,每个结点有一个权值\(w_i(|w_i\ ...

  5. Codechef October Challenge 2018 游记

    Codechef October Challenge 2018 游记 CHSERVE - Chef and Serves 题目大意: 乒乓球比赛中,双方每累计得两分就会交换一次发球权. 不过,大厨和小 ...

  6. Codechef September Challenge 2018 游记

    Codechef September Challenge 2018 游记 Magician versus Chef 题目大意: 有一排\(n(n\le10^5)\)个格子,一开始硬币在第\(x\)个格 ...

  7. codechef February Challenge 2018 简要题解

    比赛链接:https://www.codechef.com/FEB18,题面和提交记录是公开的,这里就不再贴了 Chef And His Characters 模拟题 Chef And The Pat ...

  8. BZOJ 2016: [Usaco2010]Chocolate Eating( 二分答案 )

    因为没注意到long long 就 TLE 了... 二分一下答案就Ok了.. ------------------------------------------------------------ ...

  9. codechef January Challenge 2017 简要题解

    https://www.codechef.com/JAN17 Cats and Dogs 签到题 #include<cstdio> int min(int a,int b){return ...

随机推荐

  1. Maven 虐我千百遍,我待 Maven 如初恋

    前言 在如今的互联网项目开发当中,特别是Java领域,可以说Maven随处可见.Maven的仓库管理.依赖管理.继承和聚合等特性为项目的构建提供了一整套完善的解决方案,可以说如果你搞不懂Maven,那 ...

  2. ES6 Reflect使用笔记

    Reflect Reflect 对象和Proxy对象一样, 为操作对象提供了新的API. 为什么使用 Reflect的方式来操作对象? 将 Object 对象上一些明显属于内部的方法放到 Reflec ...

  3. KVM修改虚机网卡模式:由NAT模式改为Bridge模式

    1)关闭虚机# virsh  shutdown  vm1 2)编辑虚机配置文件# virsh  edit  vm1 <interface type='default'> 改为<int ...

  4. GNU汇编程序框架

    汇编的作用:1.对芯片进行初始化 2. 和C混合编程提升C的运行效率 .section .data < 初始化的数据> .section .bss <未初始化的数据> .sec ...

  5. SpringSecurity项目报错

    启动时,提示: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory be ...

  6. C盘扩容 更改C盘大小

    最近对xamarin有点兴趣,虽然网上的评论嘘声一片, 对于只想试一试的心态来说,对于网上所说的什么开发后的程序卡顿,可以用的三方库很少等, 我只想说,你们说的我不信,我要试一试看 我本来已经安装了v ...

  7. JZOJ 3385. 【NOIP2013模拟】黑魔法师之门

    3385. [NOIP2013模拟]黑魔法师之门 (Standard IO) Time Limits: 1000 ms  Memory Limits: 131072 KB  Detailed Limi ...

  8. 权限组件(12):自动发现项目中有别名的URL

    自动发现项目中所有有别名的URL,效果如下: customer_list {'name': 'customer_list', 'url': '/customer/list/'} customer_ad ...

  9. Eclipse快速输出System.out.println();

    借鉴网上大佬博客 刚开始还好好敲代码 后来看博客发现其实输入syso或sysout 再按alt+/就OK 开始学JAVA,好好干.

  10. PAT Basic 1084

    1084 外观数列 外观数列是指具有以下特点的整数序列: d, d1, d111, d113, d11231, d112213111, ... 它从不等于 1 的数字 d 开始,序列的第 n+1 项是 ...