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

BAPC25-070.Intermill Logistics

Medium · 1 s · 256 MB

  • icpc
  • bapc
  • 2025

It is the 25th of September, 1825. Having just completed a record-setting wheat harvest, you wonder what to do with all this wheat. With a stroke of genius, you decide to use all of this wheat to bake your favourite type of cookie: stroopwafels. Of course, all this wheat should be ground to flour first. Because you cannot wait to start baking, you want to do this as fast as possible, so you decide to contact all flour mills in the Netherlands to ask them for help.

For each of these flour mills, you know how fast they can grind wheat to flour and how long it takes for a shipment to travel to and from the mill. You have enough grain ships available that can transport wheat to these mills, and bring the flour back from the mills. Dividing the wheat optimally between these mills, how long does it take until you have received back all the wheat?

As an example, consider the first sample case. To divide the wheat optimally between the three mills, you ship 400400400 kilograms to the first, 120120120 to the second, and 480480480 to the third. The first mill requires 555 hours to grind its wheat, the second requires 111 hour, and the third requires 333 hours. Combined with the shipping time to and from each mill, you receive all wheat back after exactly 111111 hours.

In the second sample case, we send all of the wheat to the first mill. This mill can grind all 100100100 kilograms of wheat in 111 hour, which together with the 222 hours for shipping back and forth results in a total of 333 hours. As the shipping for the second mill would already take 444 hours, it is optimal to only use the first mill.

Giriş formatı

The input consists of:

• One line with two integers nnn and www (1≤n≤1051\leq n\leq 10^51≤n≤105, 1≤w≤1091\leq w\leq 10^91≤w≤109), the number of mills and the amount of wheat you have, in kilograms.

• nnn lines, each with two integers ppp and ttt (1≤p,t≤1091\leq p, t\leq 10^91≤p,t≤109), describing a mill that can process ppp kilograms of wheat per hour, located ttt hours away.

Çıxış formatı

Output the number of hours until you have received back all the wheat, when dividing the wheat optimally between the mills.

Your answer should have an absolute or relative error of at most 10−610^{-6}10−6.

Qeyd

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

Nümunələr

Giriş #1

3 1000
80 3
120 5
160 4

Çıxış #1

11

Giriş #2

2 100
100 1
500 2

Çıxış #2

3

Giriş #3

3 7
1 1
1 1
1 1

Çıxış #3

4.3333333