P14635 [NOIP2025] Candy Shop
Description
Little X has opened a candy shop selling $n$ kinds of candies, with an unlimited number of candies of each kind. For different kinds of candies, Little X uses different promotion strategies. Specifically, for the $i$-th kind of candy ($1 \le i \le n$), the price of the first candy is $x_i$ yuan, the price of the second candy is $y_i$ yuan, the price of the third candy is $x_i$ yuan again, the price of the fourth candy is $y_i$ yuan, and so on.
Little R has brought $m$ yuan to buy candies. Little R does not care about the kinds of candies and only wants to get as many candies as possible. You need to help Little R find the maximum number of candies that can be bought with $m$ yuan.
Input Format
The first line of the input contains two positive integers $n, m$, denoting the number of kinds of candies and the amount of money Little R has.
The $(i+1)$-th line of the input ($1 \le i \le n$) contains two positive integers $x_i, y_i$, denoting the price of an odd-numbered candy and the price of an even-numbered candy when buying the $i$-th kind of candy respectively.
Output Format
Output one line with one non-negative integer, denoting the maximum number of candies that can be bought with $m$ yuan.
Explanation/Hint
### Sample 1 Explanation
Little R can buy $4$ candies of the first kind, spending $4 + 1 + 4 + 1 = 10$ yuan in total.
### Sample 2 Explanation
Little R can buy $1$ candy of the first kind, $1$ candy of the second kind and $6$ candies of the third kind, spending $1 + 2 + 12 = 15$ yuan in total.
### Sample 3
See `candy/candy3.in` and `candy/candy3.ans` in the contestant directory.
This sample satisfies the constraints of test $6$.
### Sample 4
See `candy/candy4.in` and `candy/candy4.ans` in the contestant directory.
This sample satisfies the constraints of tests $8,9$.
### Sample 5
See `candy/candy5.in` and `candy/candy5.ans` in the contestant directory.
This sample satisfies the constraints of tests $11,12$.
### Sample 6
See `candy/candy6.in` and `candy/candy6.ans` in the contestant directory.
This sample satisfies the constraints of test $13$.
### Sample 7
See `candy/candy7.in` and `candy/candy7.ans` in the contestant directory.
This sample satisfies the constraints of tests $17,18$.
### Constraints
For all testdata, we have:
- $1 \le n \le 10^5$;
- $1 \le m \le 10^{18}$;
- For all $1 \le i \le n$, $1 \le x_i, y_i \le 10^9$.
::cute-table{tuack}
| Test | $n \le$ | $m \le$ | Special property |
|:----------:|:-------:|:-------:|:--------:|
| $1$ | $1$ | $10$ | None |
| $2,3$ | $2$ | $20$ | ^ |
| $4,5$ | $10$ | ^ | ^ |
| $6$ | $10^2$ | $10^2$ | A |
| $7$ | ^ | ^ | B |
| $8,9$ | ^ | ^ | None |
| $10$ | $10^3$ | $10^4$ | A |
| $11,12$ | ^ | ^ | B |
| $13$ | ^ | ^ | None |
| $14$ | $10^5$ | $10^9$ | A |
| $15,16$ | ^ | ^ | B |
| $17,18$ | ^ | ^ | None |
| $19,20$ | ^ | $10^{18}$ | ^ |
Special property A: for all $1 \le i \le n$, $x_i = y_i$.
Special property B: for all $1 \le i \le n$, $x_i \ge y_i$.
Translated by QwenWork