Ex - Shojin Editorial /

Time Limit: 3 sec / Memory Limit: 1024 MB

配点 : 650

問題文

あなたは 精進 をすることにしました。精進とは、AtCoder の問題を大量に解くことをいいます。
精進は何日か掛けて行われます。1 日における精進は次の手順で行われます。

  • その日に M 問の問題を解くとする。各問題には非負整数対 (A, B)難易度 と呼ばれる値としてついている。
  • まず、M 問を自由な順番に並べ替える。そして、並び替えた後の順に問題を 1 問ずつ解いていく。
  • あなたは 疲労度 という値を持っている。1 日のはじめの疲労度は 0 であり、難易度が (A, B) である問題を解くごとに疲労度が x から Ax + B に変化する。
  • M 問すべて解いた時点での疲労度を、その日の 消費した体力 と呼ぶ。

N 問の AtCoder の問題が並んでいて、順に問題 1, 問題 2, \dots, 問題 N と呼びます。問題 i の難易度は (A_i, B_i) です。
あなたは精進を行うことで N 問の問題を全て解くことにしました。
精進は次の手順で行います。以下では問題 L, 問題 L+1, ..., 問題 R からなる問題の列を [L, R] と呼びます。

  • 1 以上 N 以下の整数 K を自由に選ぶ。精進する日数を K 日とする。
  • N 問の問題の列を、K 個の非空な連続部分列に分割して、前から i 番目の列を S_i とする。
    形式的に説明すると、狭義単調増加な非負整数列 x_0, x_1, \dots, x_K のうち 1 = x_0 かつ x_K = N + 1 を満たすものを 1 つ選び、1 \leq i \leq K について S_i = [x_{i-1}, x_i - 1] とする。
  • そして、i=1, 2, \dots, K について、 i 日目の精進では S_i に含まれる問題全てを解く。

あなたは、精進全体での消費した体力の総和が X 以下になるように精進をすることにしました。
このような精進の日数 K として取り得る最小の値を D とします。(ここで X について、\sum_{i = 1}^N B_i \leq X が保証されています。この制約下において条件を満たす D は必ず存在します。)
また、K=D である精進において、精進全体での消費した体力の総和として取り得る最小の値を M とします。

D および M を求めてください。

制約

  • 1 \leq N \leq 2 \times 10^5
  • 1 \leq X \leq 10^8
  • 1 \leq A_i \leq 10^5
  • 1 \leq B_i
  • \sum_{i=1}^N B_i \leq X
  • 入力される値は全て整数

入力

入力は以下の形式で標準入力から与えられる。

N X
A_1 B_1
A_2 B_2
\vdots
A_N B_N

出力

D および M を空白区切りで出力せよ。


入力例 1

3 100
2 2
3 4
5 7

出力例 1

1 52

このテストケースでは X に関する条件を満たしながら 1 日で全ての問題を解くことが可能です。
以下の手順で精進を行うことで、精進全体での消費した体力は 52 になり、これが最小です。

  • K=1 として、1 日目に [1, 3] を解くとする。
  • 1 日目の精進は以下の手順で行う。
    • 問題を (問題 3, 問題 2, 問題 1) の順に並べる。
    • はじめ、疲労度は 0 である。
    • 問題 3 を解く。疲労度は 5 \times 0 + 7 = 7 に変化する。
    • 問題 2 を解く。疲労度は 3 \times 7 + 4 = 25 に変化する。
    • 問題 1 を解く。疲労度は 2 \times 25 + 2 = 52 に変化する。
    • 全ての問題を解いた時点での疲労度は 52 である。よってこの日の消費した体力は 52 となる。
  • 精進全体での消費した体力の総和もまた 52 である。

入力例 2

3 30
2 2
3 4
5 7

出力例 2

2 17

このテストケースは、1 番目のテストケースの X100 から 30 に変えたものです。よって、 X に関する条件を満たしながら 1 日で全ての問題を解くことは不可能です。

以下の手順に従って精進を 2 日間行うことで M=17 を達成できます。

  • K = 2 として、1 日目に [1, 2], 2 日目に [3, 3] を解くとする。
  • 1 日目の精進は以下の手順で行う。
    • 問題を (問題 1, 問題 2) の順に並べる。
    • はじめ、疲労度は 0 である。
    • 問題 1 を解く。疲労度は 2 \times 0 + 2 = 2 に変化する。
    • 問題 2 を解く。疲労度は 3 \times 2 + 4 = 10 に変化する。
    • 全ての問題を解いた時点での疲労度は 10 である。よって 1 日目の消費した体力は 10 となる。
  • 2 日目の精進は以下の手順で行う。
    • 問題を (問題 3) の順に並べる。
    • はじめ、疲労度は 0 である。
    • 問題 3 を解く。疲労度は 5 \times 0 + 7 = 7 に変化する。
    • 全ての問題を解いた時点での疲労度は 7 である。よって 2 日目の消費した体力は 7 となる。
  • 精進全体での消費した体力の総和は 10 + 7 = 17 である。

入力例 3

5 50000000
100000 10000000
100000 10000000
100000 10000000
100000 10000000
100000 10000000

出力例 3

5 50000000

11 問ずつ解いていく精進が答えとなります。


入力例 4

10 100000000
5 88
66 4
52 1
3 1
12 1
53 25
11 12
12 2
1 20
47 10

出力例 4

2 73647

入力例 5

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

出力例 5

4 54468135

Score : 650 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 M 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).
  • First, rearrange the M 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 0, and it changes from x to Ax + B when solving a problem with difficulty (A, B).
  • The fatigue at the end of solving all M problems is called the energy consumed for that day.

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

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

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

Find D and M.

Constraints

  • 1 \leq N \leq 2 \times 10^5
  • 1 \leq X \leq 10^8
  • 1 \leq A_i \leq 10^5
  • 1 \leq B_i
  • \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:

N X
A_1 B_1
A_2 B_2
\vdots
A_N B_N

Output

Print D and M separated by a space.


Sample Input 1

3 100
2 2
3 4
5 7

Sample Output 1

1 52

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

  • Set K=1 and solve [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 3, problem 2, problem 1).
    • Initially, the fatigue is 0.
    • Solve problem 3. The fatigue changes to 5 \times 0 + 7 = 7.
    • Solve problem 2. The fatigue changes to 3 \times 7 + 4 = 25.
    • Solve problem 1. The fatigue changes to 2 \times 25 + 2 = 52.
    • The fatigue at the end of solving all problems is 52. Therefore, the energy consumed on this day is 52.
  • The total energy consumed throughout the practice is also 52.

Sample Input 2

3 30
2 2
3 4
5 7

Sample Output 2

2 17

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

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

  • Set K = 2, and solve [1, 2] on the first day and [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 1, problem 2).
    • Initially, the fatigue is 0.
    • Solve problem 1. The fatigue changes to 2 \times 0 + 2 = 2.
    • Solve problem 2. The fatigue changes to 3 \times 2 + 4 = 10.
    • The fatigue at the end of solving all problems is 10. Therefore, the energy consumed on the first day is 10.
  • Carry out the practice on the second day in the following steps.
    • Arrange the problems in the order (problem 3).
    • Initially, the fatigue is 0.
    • Solve problem 3. The fatigue changes to 5 \times 0 + 7 = 7.
    • The fatigue at the end of solving all problems is 7. Therefore, the energy consumed on the second day is 7.
  • The total energy consumed throughout the practice is 10 + 7 = 17.

Sample Input 3

5 50000000
100000 10000000
100000 10000000
100000 10000000
100000 10000000
100000 10000000

Sample Output 3

5 50000000

The optimal practice is to solve one problem per day.


Sample Input 4

10 100000000
5 88
66 4
52 1
3 1
12 1
53 25
11 12
12 2
1 20
47 10

Sample Output 4

2 73647

Sample Input 5

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

Sample Output 5

4 54468135