Codechef Challenge Forestga:forest Gathering two minutes

Source: Internet
Author: User

Description

All submissions to this problem is 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 is given initial height of the i-th tree by Hi and the rate of growth of height as Ri meters per mo Nth. For simplicity, you can assume this all the trees is 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 have 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'll able to fulfill the order. Can assume that Chef's company s sawing machines is very efficient and take negligible amount of time to cut the tree S.

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 num ber of trees in the farm, the amount of wood (in meters) that has to be gathered and the minimum allowed height of the TR EE to cut.

Each of next N lines contain the space separated integers denoting Hi and Ri respectively.

Output

Output a single integer denoting the number of months that has to pass before Chef would be able to fulfill the order.

Constraints
    • 1N
    • 1W, L1018
    • 1Hi, Ri109
Subtasks
    • Subtask #1 [points]: 1≤ N, W, L104
    • Subtask #2 [points]: No Additional constraints
Example
Input:3 9Output:7
Explanation

After 6 months, heights of each tree would be , and respectively. Chef is allowed to cut only the third tree, sadly it was not enough to fulfill an order of the meters of wood.

After 7 months, heights of each tree would be , and respectively. Now Chef was 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, HA SK, ICK, ICON, JAVA, JS, Lisp Clisp, Lisp Sbcl, LUA, NEM, Nice, NODEJS, pas fpc, pas gpc, PERL, PERL6, PHP, PIKE, PRLG, PY PY, Pyth, Pyth 3.1.2, RUBY, SCALA, SCM Chicken, SCM Guile, SCM Qobi, ST, TCL, TEXT, WSPC test instructions: Chinese noodle https://s3.amazonaws.com/ Codechef_shared/download/translated/may16/mandarin/forestga.pdf: Binary processing two-month number but here's a check that requires special handling direct calculation multiplication will explode LL skill Division processing note The * position in the code should be careful when considering the details.
1#include <iostream>2#include <cstring>3#include <cstdio>4 #definell Long Long5 using namespacestd;6 ll N,w,l;7 structnode8 {9 ll H,r;Ten}n[100005]; One BOOLCheck (ll EXM) A { -ll sum=0; -     if(exm==0) the     { -          for(intI=1; i<=n;i++) -         { -             if(n[i].h>=l) +sum+=n[i].h; -             if(sum>=W) +             { A                 return true; at             } -         } -         return false; -     } -      for(intI=1; i<=n;i++) -     { in         if((n[i].r> (l-n[i].h)/EXM) | | (n[i].r== (l-n[i].h)/exm&& (l-n[i].h)%exm==0))//********* -         { tosum=sum+n[i].h; +ll cha=w-sum; -            if(sum>=W) the            { *                 return true; $            }Panax Notoginseng            if(cha/n[i].r<=EXM) -             { the                 return true; +             } Asum=sum+exm*N[I].R; the         } +     } -     return false; $ } $ intMain () - { -      while(SCANF ("%i64d%i64d%i64d", &n,&w,&l)! =EOF) the     { -memset (N,0,sizeof(N));Wuyi      for(intI=1; i<=n;i++) thescanf"%i64d%i64d",&n[i].h,&N[I].R); -ll l=0; Wull r=W; - ll mid; About       while(l<R) $      { -Mid= (l+r) >>1; -          if(check (mid)) -R=mid; A          Else +L=mid+1; the      } -cout<<l<<Endl; $     } the     return 0; the}

Codechef Challenge Forestga:forest Gathering two minutes

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.