This page is still under construction.

Parts of this page are still being built. What you see may change.

Probe

Time limit1sMemory limit128 MB

Summary
Given range-sum probe results on a length-K binary road, find the lexicographically smallest object placement satisfying all of them, or NONE.
Level

Medium6 of 10

Topics
Array, Prefix sum, Greedy, Brute force
Solved
No attempts yet

Problem

Several special objects are buried somewhere along a straight road. Think of the road as a one-dimensional array of length KK. Each unit cell either holds one object (#) or is empty (-). In the picture below the numbers are the cell indices, and a cell marked with ▲ contains an object.

123456789101112
▲▲▲▲▲▲

Figure 1

You may inspect how many objects lie in a contiguous range using the query Probe[x, y]. If the range from xx to yy contains rr objects, we write Probe[x, y] = r (with x≤yx \le y). For example, in Figure 1 we have Probe[2, 7] = 3, Probe[2, 2] = 0, Probe[6, 9] = 4, and Probe[5, 12] = 5.

Write a program that reconstructs an arrangement of objects on the road that satisfies all of the given probe results simultaneously.

Input

The first line contains two integers KK and NN. KK is the length of the whole range and NN is the number of probe results. Each of the next NN lines contains one probe result as three space-separated integers xx yy rr, meaning Probe[x, y] = r.

Constraints: 3≤K≤403 \le K \le 40, 2≤N≤10002 \le N \le 1000, 1≤x≤y≤K1 \le x \le y \le K, 0≤r≤10000 \le r \le 1000.

Output

Print an arrangement satisfying every probe result as a string of length KK, using # for a cell that holds an object and - for an empty cell. If several arrangements satisfy all the results, print the lexicographically smallest such string (compared character by character, where # comes before -). If no arrangement satisfies all the probe results, print NONE.

Examples2

  1. Example 1

    Input
    12 7
    1 8 4
    6 10 4
    2 12 6
    9 12 2
    4 6 1
    1 4 1
    11 11 0
    
    Expected output
    -#--#-####--
    
  2. Example 2

    Input
    12 2
    1 10 1
    4 7 3
    
    Expected output
    NONE