CF81D.Polycarp's Picture Gallery

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Polycarp loves not only to take pictures, but also to show his photos to friends. On his personal website he has recently installed a widget that can display n photos with the scroll option. At each moment of time the widget displays exactly one photograph with the option showing the previous/next one. From the first photo, you can switch to the second one or to the n-th one, from the second photo you can switch to the third one or to the first one, etc. Thus, navigation is performed in a cycle.

Polycarp's collection consists of m photo albums, the i-th album contains a__i photos. Polycarp wants to choose n photos and put them on a new widget. To make watching the photos interesting to the visitors, he is going to post pictures so that no two photos from one album were neighboring (each photo will have exactly two neighbors, the first photo's neighbors are the second and the n-th one).

Help Polycarp compile a photo gallery. Select n photos from his collection and put them in such order that no two photos from one album went one after the other.

Polycarp 不仅喜欢拍照,还喜欢向朋友们展示自己的照片。他最近在个人网站上安装了一个支持滚动功能的小部件,该小部件可显示 n 张照片。在任意时刻,小部件恰好显示一张照片,并提供切换至前一张或后一张照片的选项。从第一张照片可切换至第二张或第 n 张;从第二张照片可切换至第三张或第一张;依此类推。因此,导航是以循环方式进行的。

Polycarp 的照片收藏包含 m 个相册,其中第 i 个相册含有 a__i 张照片。Polycarp 希望从中选出 n 张照片,放入这个新小部件中。为了让访客观看起来更有趣,他打算将照片排布成一种顺序,使得同一相册中的任意两张照片均不相邻(每张照片恰好有两个邻居:第一张照片的邻居是第二张和第 n 张)。

请帮助 Polycarp 构建一个照片画廊:从他的收藏中选出 n 张照片,并将它们按某种顺序排列,使得没有两张来自同一相册的照片彼此相邻。

输入格式

The first line contains two integers n and m (3 ≤ n ≤ 1000, 1 ≤ m ≤ 40), where n is the number of photos on the widget, and m is the number of albums. The second line contains m integers _a_1, _a_2, ..., a__m (1 ≤ a__i ≤ 1000), where a__i is the number of photos in the i-th album.

第一行包含两个整数 nn 和 mm(3 ≤ n ≤ 10003 \leq n \leq 1000,1 ≤ m ≤ 401 \leq m \leq 40),其中 nn 表示小部件上的照片数量,mm 表示相册数量。
第二行包含 mm 个整数 a1, a2, ..., ama_1,\,a_2,\,...,\,a_m(1 ≤ ai ≤ 10001 \leq a_i \leq 1000),其中 aia_i 表示第 ii 个相册中的照片数量。

输出格式

Print the single number -1 if there is no solution. Otherwise, print n numbers _t_1, _t_2, ..., t__n, where t__i represents the number of the album of the i-th picture in the widget. The albums are numbered from 1 in the order of their appearance in the input. If there are several solutions, print any of them.

如果无解,输出单个数字 −1-1。否则,输出 nn 个数字 t1, t2, ..., tnt_1,\,t_2,\,...,\,t_n,其中 tit_i 表示小部件中第 ii 张图片所属相册的编号。相册按其在输入中出现的顺序从 11 开始编号。若存在多个解,输出任意一个即可。

输入输出样例

  • 输入#1

    4 3
    1 3 5

    输出#1

    3 1 3 2
  • 输入#2

    10 2
    5 5

    输出#2

    2 1 2 1 2 1 2 1 2 1
  • 输入#3

    10 3
    1 10 3

    输出#3

    -1

输入解题思路,AI测评打分。不知道怎么写?

首页