atcoder#ABC305H. [ABC305Ex] Shojin

[ABC305Ex] Shojin

Score : 650650 points

Problem Statement

You have decided to practice. Practice means solving a large number of problems in AtCoder. Practice takes place over several days. The practice for one day is carried out in the following steps.

  • Let MM be the number of problems to be solved on that day. Each problem has a value called difficulty, which is a pair of non-negative integers (A,B)(A, B).
  • First, rearrange the MM problems in any order. Then, solve the problems one by one in that order.
  • You have a value called fatigue. The fatigue at the beginning of the day is 00, and it changes from xx to Ax+BAx + B when solving a problem with difficulty (A,B)(A, B).
  • The fatigue at the end of solving all MM problems is called the energy consumed for that day.

There is a sequence of NN problems in AtCoder, called problem 11, problem 22, \dots, problem NN in order. The difficulty of problem ii is (Ai,Bi)(A_i, B_i). You have decided to solve all NN problems through practice. Practice is carried out in the following steps. Below, let [L,R][L, R] denote the following sequence of problems: problem LL, problem L+1L+1, ......, problem RR.

  • Choose an integer KK freely between 11 and NN, inclusive. The practice will last KK days.
  • Divide the sequence of NN problems into KK non-empty continuous subsequences, and let SiS_i be the ii-th sequence.
    Formally, choose a strictly increasing non-negative integer sequence x0,x1,,xKx_0, x_1, \dots, x_K such that 1=x01 = x_0 and xK=N+1x_K = N + 1, and let Si=[xi1,xi1]S_i = [x_{i-1}, x_i - 1] for 1iK1 \leq i \leq K.
  • Then, for i=1,2,,Ki=1, 2, \dots, K, solve all problems in SiS_i on the ii-th day of practice.

You have decided to practice so that the total energy consumed throughout the practice is at most XX. Let DD be the minimum possible value of KK, the number of days, for such a practice. (Here, it is guaranteed that i=1NBiX\sum_{i = 1}^N B_i \leq X. Under this constraint, such DD always exists.) Also, let MM be the minimum possible total energy consumed throughout a practice such that K=DK=D.

Find DD and MM.

Constraints

  • 1N2×1051 \leq N \leq 2 \times 10^5
  • 1X1081 \leq X \leq 10^8
  • 1Ai1051 \leq A_i \leq 10^5
  • 1Bi1 \leq B_i
  • i=1NBiX\sum_{i=1}^N B_i \leq X
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

NN XX

A1A_1 B1B_1

A2A_2 B2B_2

\vdots

ANA_N BNB_N

Output

Print DD and MM separated by a space.

3 100
2 2
3 4
5 7
1 52

In this test case, you can solve all problems in one day while satisfying the condition for XX. By following the steps below, the total energy consumed during the practice will be 5252, which is the minimum.

  • Set K=1K=1 and solve [1,3][1, 3] on the first day.
  • Carry out the practice on the first day in the following steps.- Arrange the problems in the order (problem 33, problem 22, problem 11).
    • Initially, the fatigue is 00.
    • Solve problem 33. The fatigue changes to 5×0+7=75 \times 0 + 7 = 7.
    • Solve problem 22. The fatigue changes to 3×7+4=253 \times 7 + 4 = 25.
    • Solve problem 11. The fatigue changes to 2×25+2=522 \times 25 + 2 = 52.
    • The fatigue at the end of solving all problems is 5252. Therefore, the energy consumed on this day is 5252.
  • Arrange the problems in the order (problem 33, problem 22, problem 11).
  • Initially, the fatigue is 00.
  • Solve problem 33. The fatigue changes to 5×0+7=75 \times 0 + 7 = 7.
  • Solve problem 22. The fatigue changes to 3×7+4=253 \times 7 + 4 = 25.
  • Solve problem 11. The fatigue changes to 2×25+2=522 \times 25 + 2 = 52.
  • The fatigue at the end of solving all problems is 5252. Therefore, the energy consumed on this day is 5252.
  • The total energy consumed throughout the practice is also 5252.
3 30
2 2
3 4
5 7
2 17

This test case is obtained by changing XX from 100100 to 3030 in the first test case. Therefore, it is impossible to solve all problems in one day while satisfying the condition for XX.

By following the steps below, you can achieve M=17M=17 by practicing for two days.

  • Set K=2K = 2, and solve [1,2][1, 2] on the first day and [3,3][3, 3] on the second day.
  • Carry out the practice on the first day in the following steps.- Arrange the problems in the order (problem 11, problem 22).
    • Initially, the fatigue is 00.
    • Solve problem 11. The fatigue changes to 2×0+2=22 \times 0 + 2 = 2.
    • Solve problem 22. The fatigue changes to 3×2+4=103 \times 2 + 4 = 10.
    • The fatigue at the end of solving all problems is 1010. Therefore, the energy consumed on the first day is 1010.
  • Arrange the problems in the order (problem 11, problem 22).
  • Initially, the fatigue is 00.
  • Solve problem 11. The fatigue changes to 2×0+2=22 \times 0 + 2 = 2.
  • Solve problem 22. The fatigue changes to 3×2+4=103 \times 2 + 4 = 10.
  • The fatigue at the end of solving all problems is 1010. Therefore, the energy consumed on the first day is 1010.
  • Carry out the practice on the second day in the following steps.- Arrange the problems in the order (problem 33).
    • Initially, the fatigue is 00.
    • Solve problem 33. The fatigue changes to 5×0+7=75 \times 0 + 7 = 7.
    • The fatigue at the end of solving all problems is 77. Therefore, the energy consumed on the second day is 77.
  • Arrange the problems in the order (problem 33).
  • Initially, the fatigue is 00.
  • Solve problem 33. The fatigue changes to 5×0+7=75 \times 0 + 7 = 7.
  • The fatigue at the end of solving all problems is 77. Therefore, the energy consumed on the second day is 77.
  • The total energy consumed throughout the practice is 10+7=1710 + 7 = 17.
5 50000000
100000 10000000
100000 10000000
100000 10000000
100000 10000000
100000 10000000
5 50000000

The optimal practice is to solve one problem per day.

10 100000000
5 88
66 4
52 1
3 1
12 1
53 25
11 12
12 2
1 20
47 10
2 73647
15 100000000
2387 3178
2369 5772
1 29
36 3
52 2981
196 1
36 704
3 3
1501 5185
23 628
3623 810
80 101
6579 15
681 7
183 125
4 54468135