#K83667. Sequence Construction Under Conditions

    ID: 36249 Type: Default 1000ms 256MiB

Sequence Construction Under Conditions

Sequence Construction Under Conditions

You are given an integer N representing the number of elements in a sequence and an integer M representing the number of conditions. Then, M conditions follow. Each condition is of the form \( (a, b, s) \), where \(a\) and \(b\) (with 1 ≤ a ≤ b ≤ N) specify a contiguous segment of the sequence and \(s\) is the sum that the elements in that segment must add up to.

Your task is to construct a sequence \(A = [a_1, a_2, \dots, a_N]\) of integers such that, for every condition \((a, b, s)\), the following holds:

\(\displaystyle \sum_{i=a}^{b} a_i = s\)

The sequence is constructed by processing the conditions one by one in the given order. For each condition \((a, b, s)\), let \(L = b - a + 1\). Compute the quotient \(q = \lfloor s / L \rfloor\) and the remainder \(r = s \bmod L\). Then, for indices \(i = a, a+1, \dots, b\), assign:

\(a_i = q + 1\) for the first \(r\) elements, and \(a_i = q\) for the remaining \(L - r\) elements.

Note: If different conditions overlap in their segments, later conditions will override the values set by earlier conditions in the overlapping positions.

inputFormat

The first line contains two integers \(N\) and \(M\) separated by a space.

Then \(M\) lines follow. Each line has three integers \(a\), \(b\), and \(s\) separated by spaces, representing one condition.

You need to read the entire input from stdin.

outputFormat

Output the constructed sequence of \(N\) integers in one line, separated by spaces. The output should be written to stdout.

## sample
5 3
1 3 6
2 4 5
3 5 4
2 2 2 1 1

</p>