問題一覧 > 通常問題

No.448 Rain and Snow of Yukicoder (3)

レベル : / AI推定難易度 : 1650 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 61
作問者 : りあん / テスター : 37zigen
お気に入りにしたユーザー ProblemId : 1430 / 自分の提出
問題文最終更新日: 2026-06-25 12:35:56
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 154 (順位表) の他の問題:

Problem Statement

Ame was supposed to help his older sister Yuki, who runs "Yukicoder", yet again...

However, on the day of the contest, Yuki fell ill!

So this time, Ame has decided to run the contest himself!


...That said, Ame has only ever helped Yuki before, so holding a contest alone is very hard for him.

To hold a contest, certain tasks must be carried out at fixed times during, before, and after the contest, and each task has a different "difficulty" from Ame's point of view.

Ame lacks confidence, so he does not want to do tasks that are too difficult.

Therefore, he has decided to wake Yuki and ask her to handle the difficult tasks. However, he cannot push Yuki too hard, so after waking her once, he will always leave at least a certain amount of time before waking her again.

Under this constraint, Ame wants to first minimize the difficulty of the most difficult task he performs, and then, among such choices, minimize the sum of the difficulties of all the tasks he performs.


When he does so, find the difficulty of the most difficult task Ame performs and the sum of the difficulties of all the tasks Ame performs.

If Ame does not have to perform any tasks, output $0$ for both.


Note that at time $0$, Yuki is assumed to have already been sleeping continuously for a sufficiently long time.

Also, Yuki performs any task instantly, and the time it takes her to fall asleep again can be ignored.

Input

$N \ K$
$T_1 \ D_1$
$T_2 \ D_2$
 $:$
$T_N \ D_N$

The first line contains the number of tasks that must be performed, $N$, and the time $K$ for which Ame wants to let Yuki sleep continuously.

The following $N$ lines, starting from the second line, give the information of each task.

The $i \ (1 \leq i \leq N)$-th of the lines from the second line onward contains the time $T_i$ at which task $i$ is performed and the difficulty $D_i$ of task $i$, separated by a space.

All inputs are integers and satisfy the following constraints.

  • $1 \leq N \leq 2 \times 10^5$
  • $1 \leq K \leq 10^9$
  • $1 \leq T_1 \lt T_2 \lt \ ... \lt T_N \leq 10^9$
  • $1 \leq D_i \leq 10^9$

There are no partial scores, but 1_small_*.in satisfy $N, K \leq 1000, \ \ T_i \ , \ D_i \leq 10^5$.

Output

On the first line, output the difficulty of the most difficult task Ame performs.

Then, on the second line, output the sum of the difficulties of all the tasks Ame performs.

Finally, print a newline.

Sample

Sample 1
Input
5 3
4 5
5 6
7 7
8 4
11 4
Output
6
10

If Yuki performs the 1st, 3rd, and 5th tasks, the maximum difficulty of the tasks Ame performs is $6$ and the sum is $10$, which is optimal.

Sample 2
Input
9 1
1 1
2 10
3 100
4 1000
5 10000
6 100000
7 1000000
8 10000000
9 100000000
Output
0
0

Ame has no hesitation about waking Yuki, so there are no tasks for Ame to perform.

If there are no tasks for Ame to perform, output $0$ for both.

Sample 3
Input
3 8
2 6
7 9
11 5
Output
6
11

If he only wanted to minimize the sum, having Yuki perform the 1st and 3rd tasks would make the sum of the difficulties of the tasks Ame performs $9$,

but for Ame, minimizing the maximum is more important than minimizing the sum, so the answer is as shown above.

Sample 4
Input
2 1000000000
1 1000000000
1000000000 1
Output
1
1

At time $0$, Yuki has already been sleeping continuously for a sufficiently long time, so Ame can wake her at time $1$.

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。