D. Polycarp's Picture Gallery
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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 ai 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.

Input

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 a1, a2, ..., am (1 ≤ ai ≤ 1000), where ai is the number of photos in the i-th album.

Output

Print the single number -1 if there is no solution. Otherwise, print n numbers t1, t2, ..., tn, where ti 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.

Sample test(s)
Input
4 3
1 3 5
Output
3 1 3 2
Input
10 2
5 5
Output
2 1 2 1 2 1 2 1 2 1
Input
10 3
1 10 3
Output
-1
#include<cstdio>
#include<queue>
#include<algorithm>
using namespace std;
int a[],p[],co[];
typedef struct
{
int num,con;
}data;
data d[];
priority_queue<data>q;
bool operator<( data x, data y ){ return x.con<y.con;
}
int main()
{
int n,m,t,cnt,sum=,co,temp,right;
scanf("%d%d",&n,&m);
for(int i=; i<=m; i++)
{
scanf("%d",&a[i]);
if(a[i]>n/)
a[i]=n/;
sum+=a[i];
}
if(sum<n)
printf("-1");
else
{
for(int i=;i<=m;i++)
{
d[i].num=i;
d[i].con=a[i];
q.push(d[i]);
}
right=;
while(right<n)
{
data u=q.top();
q.pop();
for(int i=;i<=*u.con-&&(i+right<=n);i++)
if(i&)
p[i+right]=u.num;
else
{
data temp=q.top();
q.pop();
p[i+right]=temp.num;
temp.con--;
q.push(temp);
}
right=min(right+*u.con-,n);
}
for(int i=;i<=n;i++)
printf("%d ",p[i]); }
return ;
}

CodeForces 81D.Polycarp's Picture Gallery 乱搞的更多相关文章

  1. codeforces 653C C. Bear and Up-Down(乱搞题)

    题目链接: C. Bear and Up-Down time limit per test 2 seconds memory limit per test 256 megabytes input st ...

  2. Codeforces Gym 100203G Good elements 暴力乱搞

    原题链接:http://codeforces.com/gym/100203/attachments/download/1702/statements.pdf 题解 考虑暴力的复杂度是O(n^3),所以 ...

  3. Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2)(A.暴力,B.优先队列,C.dp乱搞)

    A. Carrot Cakes time limit per test:1 second memory limit per test:256 megabytes input:standard inpu ...

  4. Codeforces 1182D Complete Mirror 树的重心乱搞 / 树的直径 / 拓扑排序

    题意:给你一颗树,问这颗树是否存在一个根,使得对于任意两点,如果它们到根的距离相同,那么它们的度必须相等. 思路1:树的重心乱搞 根据样例发现,树的重心可能是答案,所以我们可以先判断一下树的重心可不可 ...

  5. Codeforces 538G - Berserk Robot(乱搞)

    Codeforces 题目传送门 & 洛谷题目传送门 一道很神的乱搞题 %%% 首先注意到如果直接去做,横纵坐标有关联,不好搞.这里有一个非常套路的技巧--坐标轴旋转,我们不妨将整个坐标系旋转 ...

  6. Codeforces 306D - Polygon(随机化+乱搞)

    Codeforces 题目传送门 & 洛谷题目传送门 中考终于结束了--简单写道题恢复下状态罢. 首先这一类题目肯定没法用一般的方法解决,因此考虑用一些奇淫的乱搞做法解决这道题,不难发现,如果 ...

  7. Codeforces 732e [贪心][stl乱搞]

    /* 不要低头,不要放弃,不要气馁,不要慌张 题意: 给n个插座,m个电脑.每个插座都有一个电压,每个电脑都有需求电压. 每个插座可以接若干变压器,每个变压器可以使得电压变为x/2上取整. 有无限个变 ...

  8. Codeforces 1077E (二分乱搞或者dp)

    题意:给你一个数组,可以从中选区若干种元素,但每种元素选区的个数前一种必须是后一种的2倍,选区的任意2种元素不能相同,问可以选取最多的元素个数是多少? 思路1(乱搞):记录一下每种元素的个数,然后暴力 ...

  9. codeforces 665C C. Simple Strings(乱搞)

    题目链接: C. Simple Strings time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

随机推荐

  1. Git管理本地代码(一)【转】

    转自:http://blog.csdn.net/weihan1314/article/details/8677800 版权声明:本文为博主原创文章,未经博主允许不得转载.   目录(?)[+]   安 ...

  2. avalonJS-源码阅读(一)

    写angularJS源码阅读系列的时候,写的太垃圾了.一个月后看,真心不忍直视,以后有机会的话得重写.这次写avalonJS,希望能在代码架构层面多些一点,少上源码.多写思路. avalon暴露句柄方 ...

  3. oracle11g的冷热备份

    1.冷备份 如果数据库可以正常关闭,而且允许关闭足够长的时间,那么就可以采用冷备份(脱机备份),可以是归档冷备份,也可以是非归档冷备份.其方法是首先关闭数据库,然后备份所有的物理文件,包括数据文件.控 ...

  4. .net 下的集合

    集合的操作在编码的时候很常见.但是由于经常使用几种集合.而忽略了一些不常用的集合.在这里我整理下. 首先先了解下接口: 1.IEnumerable,返回一个循环访问集合的枚举器. 2.IEnumera ...

  5. springquartz的LocalDataSourceJobStore

    spring 为quartz 提供了一个 继承 JobStoreCMT的 LocalDataSourceJobStore,主要是为了和spring更好的集成. public class LocalDa ...

  6. 005_MAC下的VMware fushion快捷键(折中)

    由于MAC和VMware Fushion虚拟机之间有一些快捷键的映射,所以Windows虚拟机就找了一个折中的方案.现总结MAC下的win常用快捷键==> <1>最小化窗口(Alt ...

  7. Windows 8 应用程序前后台切换事件监听

    在一些情况下,我们需要监听应用程序切换到后台或者从后台切换至前台的事件,从而进行相关处理操作.支付宝应用锁屏(IOS,Android平台)的处理中就需要监听此事件,在用户将应用切换至后台一段时间后再切 ...

  8. drop out为什么能够防止过拟合

    来源知乎: dropout 的过程好像很奇怪,为什么说它可以解决过拟合呢?(正则化) 取平均的作用: 先回到正常的模型(没有dropout),我们用相同的训练数据去训练5个不同的神经网络,一般会得到5 ...

  9. ubuntu12.04安装ruby2.3

    为了搭建github-pages博客,而github-pages后端依赖于ruby,且对版本有严格要求,自己尝试了各种姿势升级ruby2.3无果,最终在查阅了各种资料之后找到一个可行方案. icebu ...

  10. Spring cloud Feign 调用端不生效

    如果提供方的接口经过测试是没问题的话. 消费方启动类加上@EnableFeignClients 注意定义的接口如果不和启动类在同一个包路径下,需要加basePackages 即:@EnableFeig ...