Dreamoon Likes Coloring CodeForces - 1330C(贪心+思维)
Dreamoon likes coloring cells very much.
There is a row of n cells. Initially, all cells are empty (don’t contain any color). Cells are numbered from 1 to n.
You are given an integer m and m integers l1,l2,…,lm (1≤li≤n)
Dreamoon will perform m operations.
In i-th operation, Dreamoon will choose a number pi from range [1,n?li+1] (inclusive) and will paint all cells from pi to pi+li?1 (inclusive) in i-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 m operations, all colors will appear at least once and all cells will be colored. Please help Dreamoon to choose pi in each operation to satisfy all constraints.
Input
The first line contains two integers n,m (1≤m≤n≤100000).
The second line contains m integers l1,l2,…,lm (1≤li≤n).
Output
If it’s impossible to perform m operations to satisfy all constraints, print “’-1” (without quotes).
Otherwise, print m integers p1,p2,…,pm (1≤pi≤n?li+1), after these m operations, all colors should appear at least once and all cells should be colored.
If there are several possible solutions, you can print any.
Examples
Input
5 3
3 2 2
Output
2 4 1
Input
10 1
1
Output
-1
思路:
首先考慮-1的情況:如果總共的長度小于n的話,肯定不行。如果對于其中的某一個元素a[i],如果a[i]>n-i+1,這樣也是不可以的。我們最貪心的考慮,第i個顏色是在i位開頭,如果第i個顏色在第i位開頭的話,長度超出了界限,那么它只能往前靠了。但是這樣的話,就會覆蓋前面的顏色了。如圖所示:
④這條線就不符合了。
判斷完-1的情況,那么就該考慮應該怎么貪心去放置這些顏色了。
如果第i個位置的顏色加上第i位之后顏色長度的總和(包括i)大于等于n的話,那么當前顏色要放置在i了,不能再往左靠了,可以往右靠,但是我們貪心的話,這樣是最優的。如果上面的條件不符合的話,那就要盡量的往右靠,直到總和等于n就行。
代碼如下:
努力加油a啊,(o)/~
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
以上是生活随笔為你收集整理的Dreamoon Likes Coloring CodeForces - 1330C(贪心+思维)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 派拉蒙新片《龙与地下城》超级碗预告发布,
- 下一篇: 幻读是什么?(幻读到底是什么)