#P2707. Facer 帮父亲

Facer 帮父亲

Description

Facer's father is a manager and is now always dejected.

Facer asked his father, what's wrong? His father said, the company has a problem.

The company manages nn scenic spots, each of which has many visitors.

But now, people complain that the ticket prices are too high, so he has to adjust the prices.

Specifically, for the ii-th scenic spot, if the ticket price is xx, the number of visitors is max((aibi×x),0)\max( (a_i - b_i\times x),0 ).

You need to assign the ticket price for each scenic spot such that the sum of ticket prices over all scenic spots does not exceed kk, and find the maximum revenue.

Input Format

The first line contains two integers n,kn, k.

Then follow nn lines, each containing two integers ai,bia_i, b_i.

Output Format

One line, indicating the maximum revenue.

2 4
50 2
40 1
171

Hint

Sample explanation:

Scenic spot 11 ticket price is 33, scenic spot 22 ticket price is 11.

Scenic spot 11 visitors: 503×2=4450 - 3\times 2 = 44, revenue: 132132.

Scenic spot 22 visitors: 401×1=3940 - 1\times 1 = 39, revenue: 3939.

The total revenue is 171171.

  • For 10%10\% of the testdata, 1n51 \le n \le 5, 1k51 \le k \le 5.
  • For 30%30\% of the testdata, 1n1001 \le n \le 100, 1k1001 \le k \le 100.
  • For 60%60\% of the testdata, 1n20001 \le n \le 2000, 1k20001 \le k \le 2000.
  • For 100%100\% of the testdata, 1n1000001 \le n \le 100000, 1k1000001 \le k \le 100000, 1ai,bi1000001 \le a_i, b_i \le 100000.

Thanks to zhouyonglong for providing the solution.

Translated by ChatGPT 5