King
Time limit1sMemory limit128 MB
Given weighted inequalities on subarray sums, decide whether some integer sequence satisfies all the bounds; output which phrase tells the answer.
- Level
Medium6 of 10
- Topics
- Graph, Shortest path, Prefix sum, Implementation
- Solved
- No attempts yet
Problem
A queen once gave birth to a son who would become king. Sadly, the prince could do very little arithmetic: he could only add integers and compare a sum against a single given integer bound. Moreover, the numbers he worked with had to be arranged in one sequence, and he could only add up contiguous parts of that sequence.
So that his son could rule after him, the old king decreed that every matter of state be presented as a finite sequence of integers, and every decision be made as an integer bound (an upper or lower limit) on the sum of that sequence.
After the old king died, the young king began to reign, and his decisions soon made him enemies. His opponents brought him a set of problems phrased as subsequences of a single integer sequence . For each subsequence the king declared an integer bound on its sum, in one of the two forms
Later the king realized that some of his declared bounds were mutually inconsistent. He cannot take back a declaration, but he can forge the underlying sequence. Help his advisors: decide whether there exists an integer sequence that satisfies all of the declared bounds.
Input
The input consists of several blocks. Every block except the last describes one set of decisions.
The first line of a block contains two integers and , where is the length of the sequence and is the number of bounds.
Each of the next lines contains one bound as four values :
- and select the subsequence ;
- is the comparison operator, given as
gtfor orltfor ; - is the integer bound applied to the sum of that subsequence.
The last block is a single line containing 0 and must not be processed.
Output
For each block, print one line:
successful conspiracyif no integer sequence can satisfy all of the block's bounds;lamentable kingdomotherwise.
Print nothing for the final 0 block.