CF BUDDY
← Problems·

1329A · Dreamoon Likes Coloring

1800 · constructive algorithms, greedy, implementation

Problem: Dreamoon likes coloring cells very much.

There is a row of nn cells. Initially, all cells are empty (don't contain any color). Cells are numbered from 11 to nn.

You are given an integer mm and mm integers l1,l2,,lml_1, l_2, \ldots, l_m (1lin1 \le l_i \le n)

Dreamoon will perform mm operations.

In ii-th operation, Dreamoon will choose a number pip_i from range [1,nli+1][1, n-l_i+1] (inclusive) and will paint all cells from pip_i to pi+li1p_i+l_i-1 (inclusive) in ii-th color. Note that cells may be colored more one than once, in this case, cell will have the color from the latest operation.

Dreamoon hopes that after these mm operations, all colors will appear at least once and all cells will be colored. Please help Dreamoon to choose pip_i in each operation to satisfy all constraints.

Input Format: The first line contains two integers n,mn,m (1mn1000001 \leq m \leq n \leq 100\,000).

The second line contains mm integers l1,l2,,lml_1, l_2, \ldots, l_m (1lin1 \leq l_i \leq n).

Output Format: If it's impossible to perform mm operations to satisfy all constraints, print "'-1" (without quotes).

Otherwise, print mm integers p1,p2,,pmp_1, p_2, \ldots, p_m (1pinli+11 \leq p_i \leq n - l_i + 1), after these mm operations, all colors should appear at least once and all cells should be colored.

If there are several possible solutions, you can print any.

Sample Cases

Case 1

Input

5 3
3 2 2

Output

2 4 1

Case 2

Input

10 1
1

Output

-1

Similar problems

00:00:00
Loading editor…
Welcome! I'm your coding tutor for this problem. Use the chips below to reveal stored hints or get AI feedback on your code. I'll guide you step by step — never giving away the solution.

Sign in to unlock AI tutor feedback