PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#CC0000074. Xếp những viên gạch dài (Long Bricks)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Xếp những viên gạch dài (Long Bricks)
Long Bricks
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
There are adjacent cells, initially all at height . Place bricks in order. Brick covers every cell from through , inclusive, and rests on the highest surface within its range. Output the top height of each brick after placing it.
Input
The first line contains , followed by lines containing .
Output
Print lines; line is the top height of the -th brick.
Subtasks
- Subtask 1 (20 points): ; ; .
- Subtask 2 (30 points): ; ; .
- Subtask 3 (50 points): ; ; .
Examples
Input
3 5
1 2
2 2
2 3
3 3
1 2
Output
1
2
3
4
4
Explanation
The first brick reaches height , the second , the third , and the fourth . For the fifth brick, the maximum height over cells is , so its top becomes .