#CC0000076. Mô tả bức tranh pha màu (Describe the Painting)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Mô tả bức tranh pha màu (Describe the Painting)
Describe the Painting
Source: LeetCode
Version: Phuoc Hung OJ Extended
Problem Statement
A painting lies along a number line. Segment colors the half-open interval with a unique color code . Overlapping colors form a set; its displayed value is the sum of color codes in that set. Describe the painting by the minimum number of consecutive painted segments on which the set of colors does not change. Equal sums alone do not imply equal color sets.
Input
The first line contains , followed by lines of . This is a stdin/stdout adaptation of a LeetCode function problem.
Output
Print the number of resulting segments, then lines in increasing left-coordinate order, each containing for a painted half-open segment.
Subtasks
- Subtask 1 (20 points): ; ; ; all are distinct.
- Subtask 2 (30 points): ; ; ; all are distinct.
- Subtask 3 (50 points): ; ; ; all are distinct.
Examples
Input
4
1 4 5
1 4 7
4 7 1
4 7 11
Output
2
1 4 12
4 7 12
Explanation
On the active colors are (sum ). On the colors are (also sum ). The color sets differ, so the two pieces must remain separate.