City
Time limit3sMemory limit1024 MB
Assign distinct heights 1 to N to N buildings so that at least M-1 of the M segment minimum-height requirements hold, or report that no plan exists.
- Level
Medium7 of 10
- Topics
- Greedy, Segment tree, Array
- Solved
- No attempts yet
Problem
A property developer wants to build buildings on a new street, numbered to . To keep the street skyline varied, the city council requires that each building has between and floors, and that no two buildings have the same height.
The council also has additional requirements. Each one sets a minimum height for the buildings in one segment of the street. Because the project is important, the council is willing to drop one of the additional requirements if needed.
Find a valid construction plan, or determine that none exists.
Input
The first line contains and (, ). Each of the next lines contains three integers , , (, ). This means that every building from to (inclusive) must have at least floors.
Output
If no plan exists, print EI SAA on a single line. Otherwise, print SAAB on the first line and integers on the second line, giving the heights of buildings to . The plan must satisfy at least of the given requirements. If several plans are possible, print any of them.