#P15958. [ICPC 2018 Jakarta R] Lexical Sign Sequence
[ICPC 2018 Jakarta R] Lexical Sign Sequence
题目描述
Andi likes numbers and sequences, especially, sign sequences. A sign sequence is a sequence which consists of and . Andi is a curious person, thus, he wants to build a sign sequence which length is (the positions are numbered from to , inclusive).
However, Andi also likes some challenges. Therefore, he prefilled some positions in the sequence with or (the number in these positions cannot be changed). Andi also wants the sequence to fulfill constraints. For each constraint, there are 3 numbers: , , and . This means that the sum of numbers which position is in the range (inclusive) must be at least .
Sounds confusing, right? It is not done yet. Since there can be many sequences that fulfill all the criteria above, Andi wants the sequence to be lexicographically smallest. Sequence is lexicographically smaller than sequence if and only if there exists a position where and for all .
Find the sequence Andi wants.
输入格式
Input begins with a line containing two integers: (; ) representing the length of the sequence and the number of constraints, respectively. The second line contains integers: (). If , then the position in the sequence is not prefilled, otherwise the position in the sequence is prefilled by . The next lines, each contains three integers: (; ) representing the constraint.
输出格式
Output contains integers (each separated by a single space) in a line representing the sequence that Andi wants if there exists such sequence, or “Impossible” (without quotes) otherwise.
3 2
0 0 0
1 2 2
2 3 -1
1 1 -1
3 2
0 -1 0
1 2 2
2 3 -1
Impossible
提示
Explanation for the sample input/output #1
Both sequences and satisfy the prefilled conditions and the given constraints. The former is lexicographically smaller.
Explanation for the sample input/output #2
The second position is already prefilled with , so it is impossible to fulfill the first constraint. There is no valid sequence in this case.