#abc303f. F - Damage over Time

F - Damage over Time

Score : 525525 points

问题陈述

一个拥有 HH 点生命值的怪物出现在你面前,一场回合制战斗开始了。

在每个回合 1,2,1,2,\dots 中,你可以施放 NN 种法术中的任意一种,法术编号分别为 1,,N1,\dots,N

若你在第 jj 回合施放了第 ii 个法术,则在回合 j,j+1,,j+ti1j,j+1,\dots,j+t_i-1 中,怪物的生命值每回合减少 did_i 点。

请找出最早可以在哪个回合使怪物的生命值降至 00 或以下。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

A monster with health HH has appeared in front of you, and a turn-based battle has started.

In each turn 1,2,1,2,…, you cast one of NN spells, spells 1,,N1,…,N.

If you cast spell ii in turn jj, the monster's health reduces by did_i in each turn j,j+1,,j+ti1j,j+1,…,j+t_i -1.

Find the earliest turn that you can make the monster's health 00 or less.

Constraints

  • 1N3×1051 \leq N \leq 3 \times 10^5
  • 1H10181 \leq H \leq 10^{18}
  • 1ti,di1091 \leq t_i,d_i \leq 10^9
  • All values in the input are integers.

Input

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

NN HH

t1t_1 d1d_1

\vdots

tNt_N dNd_N

Output

Print the answer.

Sample Input 1

2 20
2 2
5 1

Sample Output 1

6

The following procedure makes the monster's health 00 or less in turn 66, which is the earliest.

  • Cast spell 11 in turn 11. Due to the spell cast in turn 11, the monster's health reduces by 22 and becomes 1818.
  • Cast spell 22 in turn 22. Due to the spells cast in turns 11 and 22, the monster's health reduces by 2+1=32+1=3 and becomes 1515.
  • Cast spell 11 in turn 33. Due to the spells cast in turns 22 and 33, the monster's health reduces by 1+2=31+2=3 and becomes 1212.
  • Cast spell 22 in turn 44. Due to the spells cast in turns 2,32,3 and 44, the monster's health reduces by 1+2+1=41+2+1=4 and becomes 88.
  • Cast spell 11 in turn 55. Due to the spells cast in turns 2,42,4 and 55, the monster's health reduces by 1+1+2=41+1+2=4 and becomes 44.
  • Cast spell 22 in turn 66. Due to the spells cast in turns 2,4,52,4,5 and 66, the monster's health reduces by 1+1+2+1=51+1+2+1=5 and becomes 1-1.

Sample Input 2

10 200
1 21
1 1
1 1
8 4
30 1
3 1
10 2
8 1
9 1
4 4

Sample Output 2

9

update @ 2024/3/10 08:32:11