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

  • 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

技巧除法处理 注意代码中的*位置 除的时候要注意考虑细节问题

 1 #include<iostream>
 2 #include<cstring>
 3 #include<cstdio>
 4 #define ll  long long
 5 using namespace std;
 6 ll n,w,l;
 7 struct node
 8 {
 9     ll h,r;
10 }N[100005];
11 bool check(ll exm)
12 {
13     ll sum=0;
14     if(exm==0)
15     {
16         for(int i=1;i<=n;i++)
17         {
18             if(N[i].h>=l)
19                 sum+=N[i].h;
20             if(sum>=w)
21             {
22                 return true;
23             }
24         }
25         return false;
26     }
27     for(int i=1;i<=n;i++)
28     {
29         if((N[i].r>(l-N[i].h)/exm)||(N[i].r==(l-N[i].h)/exm&&(l-N[i].h)%exm==0))//*********
30         {
31            sum=sum+N[i].h;
32            ll cha=w-sum;
33            if(sum>=w)
34            {
35                 return true;
36            }
37            if(cha/N[i].r<=exm)
38             {
39                 return true;
40             }
41            sum=sum+exm*N[i].r;
42         }
43     }
44     return false;
45 }
46 int main()
47 {
48     while(scanf("%I64d %I64d %I64d",&n,&w,&l)!=EOF)
49     {
50         memset(N,0,sizeof(N));
51     for(int i=1;i<=n;i++)
52         scanf("%I64d %I64d",&N[i].h,&N[i].r);
53     ll l=0;
54     ll r=w;
55     ll mid;
56      while(l<r)
57      {
58          mid=(l+r)>>1;
59          if(check(mid))
60             r=mid;
61          else
62             l=mid+1;
63      }
64      cout<<l<<endl;
65     }
66     return 0;
67 }
时间: 2024-08-27 14:25:41

codechef May Challenge 2016 FORESTGA: Forest Gathering 二分的相关文章

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

Description All submissions for this problem are available. Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Chef is a big fan of soccer! He loves soccer so much, that he even invented soccer for his pet dogs! Here are th

Codechef October Challenge 2018 游记

Codechef October Challenge 2018 游记 CHSERVE - Chef and Serves 题目大意: 乒乓球比赛中,双方每累计得两分就会交换一次发球权. 不过,大厨和小厨用了另外一种规则:双方每累计得 K 分才会交换发球权.比赛开始时,由大厨发球. 给定大厨和小厨的当前得分(分别记为 P1 和 P2),请求出接下来由谁发球. 思路: \((P1+P2)\%K\)判断奇偶性即可. 代码链接 BITOBYT - Byte to Bit 题目大意: 在字节国里有三类居民

Codechef July Challenge 2014部分题解

Dish Owner(并查集) 链接:http://www.codechef.com/JULY14/problems/DISHOWN/ 题意分析:本题主要操作就是给出0 x y时,拥有第x道菜的厨师与拥有第y道菜的厨师pk,谁拥有的所有菜的其中一道菜(不一定是x或y)的分值比较高谁就获胜,并赢得loser的所有菜.即比较的是每个人分值最高的菜,所以对于非loser的人来说,他的分值最高的菜是不变的.综合题意用并查集易解. #include <cstdio> const int Maxn=100

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

因为没注意到long long 就 TLE 了... 二分一下答案就Ok了.. ------------------------------------------------------------------------------ #include<cstdio> #include<cstring> #include<algorithm> #include<iostream> #define rep( i , n ) for( int i = 0 ;

Maximum number, GCD condition (codechef March Challenge 2014)

题目 : http://acm.bnu.edu.cn/v3/problem_show.php?pid=40489 最近做到的一道蛮有意思的题目(codechef现在的题目确实很赞了) 题意 :中文题面 (cc的一大好处就是有中文翻译,嘿嘿) 区间Max = max{a_i|gcd(a_i, g) > 1 && x <= i <= y} 做法 : 一开始我是用分块做的,复杂的O(m * sqrt(n) * C) C 是所含不同素数的个数, C大概最大只有6或7吧 然后裸裸的

Codechef March Challenge 2014——The Street

The Street Problem Code: STREETTA https://www.codechef.com/problems/STREETTA Submit Tweet All submissions for this problem are available. Read problems statements in Mandarin Chineseand Russian. The String street is known as the busiest street in Cod

CF&amp;&amp;CC百套计划2 CodeChef December Challenge 2017 Chef And his Cake

https://www.codechef.com/DEC17/problems/GIT01 #include<cstdio> #include<algorithm> using namespace std; #define N 101 char s[N]; int main() { int T; scanf("%d",&T); int n,m; int OddG,OddR,EvenG,EvenR; int ans; while(T--) { OddG=O

CF&amp;&amp;CC百套计划2 CodeChef December Challenge 2017 Chef and Hamming Distance of arrays

https://www.codechef.com/DEC17/problems/CHEFHAM #include<cstdio> #include<cstring> #include<iostream> using namespace std; #define N 100001 int a[N],b[N]; int sum[N],wh[N][2]; int num1[N],num2[N]; void read(int &x) { x=0; char c=getc

CF&amp;&amp;CC百套计划2 CodeChef December Challenge 2017 Total Diamonds

https://www.codechef.com/DEC17/problems/VK18 #include<cstdio> #include<iostream> #include<algorithm> using namespace std; #define N 1000001 long long sum[N*2],dp[N]; int num[11]; void read(int &x) { x=0; char c=getchar(); while(!isdi