AlgoLensArena
ContestlərProblemlərOtaqlar
Vizualizator
← Məsələlər

BAPC18-087.Financial Planning

Medium · 1 s · 256 MB

  • icpc
  • bapc
  • 2018

Being a responsible young adult, you have decided to start planning for retirement. Doing some back-of-the-envelope calculations, you figured out you need at least MMM euros to retire comfortably.

You are currently broke, but fortunately a generous gazillionaire friend has offered to lend you an arbitrary amount of money (as much as you need), without interest, to invest in the stock market. After making some profits you will then return the original sum to your friend, leaving you with the remainder.

Available to you are nnn investment opportunities, the iii-th of which costs cic_ici​ euros. You also used your computer science skills to predict that the iii-th investment will earn you pip_ipi​ euros per day. What is the minimum number of days you need before you can pay back your friend and retire?

For example, consider the first sample. If you buy only the second investment (which costs 151515 euros) you will earn p2=10p_2 = 10p2​=10 euros per day. After two days you will have earned 202020 euros, exactly enough to pay off your friend (from whom you borrowed 151515 euros) and retire with the remaining profits (555 euros). There is no way to make a net amount of 5 euros in a single day, so two days is the fastest possible.

Giriş formatı

• The first line contains the number of investment options 1≤n≤1051 \leq n \leq 10^51≤n≤105 and the minimum amount of money you need to retire 1≤M≤1091 \leq M \leq 10^91≤M≤109.

• Then, nnn lines follow. Each line iii has two integers: the daily profits of this investment 1≤pi≤109{1 \leq p_i \leq 10^9}1≤pi​≤109 and its initial cost 1≤ci≤1091 \leq c_i \leq 10^91≤ci​≤109.

Çıxış formatı

Print the minimum number of days needed to recoup your investments and retire with at least MMM euros, if you follow an optimal investment strategy.

Qeyd

Source: Benelux Algorithm Programming Contest 2018 · Author: Timon Knigge · License: CC BY-SA 4.0 · Original: https://bapc.eu · Statement adapted for AlgoLens and shared under the same license. · 9 of the 37 original test cases (the largest) are omitted here to keep the problem lightweight.

Nümunələr

Giriş #1

2 5
4 10
10 15

Çıxış #1

2

Giriş #2

4 10
1 8
3 12
4 17
10 100

Çıxış #2

6

Giriş #3

3 5
4 1
9 10
6 3

Çıxış #3

1