QOJ.ac

QOJ

时间限制: 2 s 内存限制: 512 MB 总分: 100

#8362. game

统计

You have recently been learning how to play games.

There are $n$ monsters. Defeating the $i$-th monster costs $A_i$ stamina, and after defeating it, you gain $B_i$ stamina. At any moment, your stamina cannot be negative.

For each $k = 1, 2, \cdots, n$, find the minimum initial stamina required to defeat $k$ monsters.

Input

The first line contains two positive integers $n$ and $m$.

The next $n$ lines each contain two integers $A_i$ and $B_i$, representing the attributes of the monsters.

Output

Output a single line containing $n$ non-negative integers, where the $i$-th integer represents the minimum initial stamina required to defeat $i$ monsters.

Examples

Input 1

4
1 2
3 4
1 1
2 3

Output 1

1 2 3 4

Input 2

8
304 282
773 724
274 481
43 254
813 110
722 107
140 62
351 418

Output 2

43 43 63 63 63 288 341 1044

Constraints

  • Subtask 1 (5 points): $n \leq 16$.
  • Subtask 2 (27 points): $n \leq 7000$.
  • Subtask 3 (68 points): No additional constraints.

For 100% of the data, $1 \leq n \leq 3 \times 10^5$ and $1 \leq A_i, B_i \leq 10^9$.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.