#P16695. [CSPro 29] 垦田计划

[CSPro 29] 垦田计划

Background

Luogu’s testdata is for community communication only and is not official testdata. Official judging link: https://www.cspro.org/.

Problem Description

Dundun selected a total of nn regions to reclaim into farmland. Since the regions have different sizes, the time needed to reclaim them is also different. It is estimated that the reclamation time of region ii (1≤i≤n1 \le i \le n) is tit_i days. These nn regions can be reclaimed at the same time, so the total time tTotalt_{Total} depends on the region that takes the longest time, namely:

$$\begin{aligned} t_{Total} = \max\{t_1, t_2, \cdots, t_n\} \end{aligned}$$

To speed up the progress, Dundun plans to invest extra resources in some regions to reduce the reclamation time. Specifically:

  • For region ii, every time you invest cic_i units of resources, you can reduce its reclamation time by 11 day.
  • The number of days reduced must be an integer, meaning the amount of resources invested in region ii must be an integer multiple of cic_i.
  • For region ii, you can invest at most ci×(ti−k)c_i \times (t_i - k) units of resources to reduce its reclamation time to kk days.
  • Here, kk is the minimum number of days to reclaim one region, satisfying 0<k≤min⁡{t1,t2,⋯ ,tn}0 < k \le \min\{t_1, t_2, \cdots, t_n\}. In other words, if resources were unlimited, all regions could be reclaimed in kk days.

Now Dundun has a total of mm units of resources available. Compute the minimum number of days needed to reclaim all nn regions.

Input Format

Read input from standard input.

There are n+1n + 1 lines in total.

The first line contains three positive integers nn, mm, and kk separated by spaces, representing the total number of regions to be reclaimed, the amount of resources Dundun has, and the minimum reclamation days for each region.

The next nn lines each contain two positive integers tit_i and cic_i separated by spaces, representing the reclamation time of region ii and the amount of resources needed to reduce the time by 11 day.

Output Format

Write output to standard output.

Output one integer, representing the minimum total time to reclaim the nn regions.

4 9 2
6 1
5 1
6 2
7 1
5
4 30 2
6 1
5 1
6 2
7 1
2

Hint

Explanation for Sample 1

As shown in the table below, investing 55 units of resources can reduce the total time to 55 days. At this point, Dundun still has 44 units of resources left, but no matter how they are allocated, the total time cannot be reduced further.

ii Base time tit_i Resources needed to reduce 11 day cic_i Resources invested Actual time
11 66 11 55
22 55 ^ 00 ^
33 66 22
44 77 11 ^

Explanation for Sample 2

By investing 2020 units of resources, you can reduce the reclamation time of all regions to exactly k=2k = 2 days. Due to the limit kk, the remaining 1010 units of resources cannot reduce the time any further.

Subtasks

70%70\% of the testdata satisfies: 0<n,ti,ci≤1000 < n, t_i, c_i \le 100 and 0<m≤1060 < m \le 10^6.

All testdata satisfies: 0<n,ti,ci≤1050 < n, t_i, c_i \le 10^5 and 0<m≤1090 < m \le 10^9.

Translated by ChatGPT 5