Paper Strips | 프로그래밍의 벗 PivotOJ
PivotOJ

Paper Strips

시간 제한: 6000ms메모리 제한: 1024MB출처: EIO 2014-15 openBOJ 7192
이 문제는 본문 이미지 일부가 표시되지 않습니다. 텍스트만으로 풀이가 어려울 수 있습니다.

문제

Jack has an LL cm long black strip of paper. He will glue colored strips of paper onto the black one. It may be assumed the new strips will always fit on top of the black one. All the strips have the same width. Each new strip will hide the colors under it.

Find the colors and lengths of the segments visible in the end.

입력

The first line of input contains the length of the black strip LL and the number of the colored strips NN. Each of the following NN lines contains three integers describing one colored strip: the color code KK (1 &le; K &le; 100) and the distance AA of the beginning and the distance BB of the end of the colored strip from the beginning of the black strip (0 &le; A < B &le; L). The code of color black is 00. Only the initial strip is black, all others are colored.

출력

The output should contain the colors and lengths of the segments of each color in the final result, listed from the beginning of the original black strip to its end. Adjacent strip sections of the same color should be output as one segment.

힌트

[이미지 1]

예제

예제 1

입력
20 4
1 2 10
2 5 8
3 3 6
3 5 7
출력
0 2
1 1
3 4
2 1
1 2
0 10
코드를 제출하려면 로그인하세요.