PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#CC0000079. Những hình vuông rơi xuống (Falling Squares)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Những hình vuông rơi xuống (Falling Squares)
Falling Squares
Source: LeetCode
Version: Phuoc Hung OJ Extended
Problem Statement
Squares fall one at a time, with left coordinate and side length . Each square lands on the ground or the top of an earlier square. Merely touching at a vertical side does not support another square. After each drop, output the greatest height reached so far.
Input
The first line contains , followed by lines . This is the stdin/stdout adaptation of LeetCode.
Output
Print lines, each giving the maximum height after that drop.
Subtasks
- Subtask 1 (20 points): ; ; .
- Subtask 2 (30 points): ; ; .
- Subtask 3 (50 points): ; ; .
Examples
Input
3
1 2
2 3
6 1
Output
2
5
5
Explanation
The first square covers and reaches height . The second covers , overlaps the first and reaches height . The third is separate, so the maximum remains .