#P10387. [蓝桥杯 2024 省 A] 训练士兵

[蓝桥杯 2024 省 A] 训练士兵

Problem Description

In the Lanqiao Kingdom, there are nn soldiers. These soldiers need to take a series of special trainings to improve their combat skills. For the ii-th soldier, the cost of one training is pip_i gold coins, and to become a top warrior, he needs at least cic_i trainings.

To make training more efficient, the kingdom provides a "group training" plan. This plan includes one required training for each soldier, and the total cost is only SS gold coins (the group training plan can be purchased multiple times, which means soldiers can take group training multiple times).

As the training commander, please compute the minimum number of gold coins needed to make all soldiers become top warriors.

Input Format

The first line contains two integers nn and SS, separated by a space, representing the number of soldiers and the cost of one group training.
The next nn lines each contain two integers pip_i and cic_i, separated by a space, representing the cost of one training for the ii-th soldier and the number of trainings required to become a top warrior.

Output Format

Output one line containing one integer, representing the minimum number of gold coins needed to make all soldiers become top warriors.

3 6
5 2
2 4
3 2
16

Hint

The training method with the minimum cost is: do group training 22 times, costing 2×6=122 \times 6 = 12 gold coins. At this point, soldiers 11 and 33 have become top warriors. Then spend another 44 gold coins to let soldier 22 do two more trainings and become a top warrior. The total cost is 12+4=1612 + 4 = 16.

For 40%40\% of the testdata, 1n1031 \le n \le 10^3, 1pi,ci1051 \le p_i, c_i \le 10^5, 1S1071 \le S \le 10^7.

For all testdata, 1n1051 \le n \le 10^5, 1pi,ci1061 \le p_i, c_i \le 10^6, 1S10101 \le S \le 10^{10}.

Translated by ChatGPT 5