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就行。
代码如下:

#include<bits/stdc++.h>
#define ll long long
using namespace std;const int maxx=2e5+100;
int a[maxx];
int ans[maxx];
ll sum[maxx];
int n,m;inline int check()
{for(int i=1;i<=m;i++) if(a[i]>n-i+1) return 1;return 0;
}
int main()
{scanf("%d%d",&n,&m);for(int i=1;i<=m;i++) {scanf("%d",&a[i]);sum[i]=sum[i-1]+a[i];}if(sum[m]<n) cout<<-1<<endl;else if(check()) cout<<-1<<endl;else{int pos=0;for(int i=1;i<=m;i++){if(i+sum[m]-sum[i-1]-1>=n) ans[i]=i;else{int j=n-(sum[m]-sum[i-1]-1);//while(j+sum[m]-sum[i-1]-1<n) j++;ans[i]=j;}cout<<ans[i]<<" ";}cout<<endl;}return 0;
}

努力加油a啊,(o)/~

Dreamoon Likes Coloring CodeForces - 1330C(贪心+思维)相关推荐

  1. Codeforces Round #631 (Div. 2) C. Dreamoon Likes Coloring 构造

    传送门 文章目录 题意: 思路: 题意: 思路: 针灸思维不行,数据结构来凑呗. 一开始做的时候想简单了,一直wawawa,后来想到了hackhackhack样例,开始换思路构造,结果死活想不到O(m ...

  2. Dreamoon Likes Sequences CodeForces - 1330D(组合数学+位运算)

    Dreamoon likes sequences very much. So he created a problem about the sequence that you can't find i ...

  3. Codeforces Round #631 (Div. 2) D. Dreamoon Likes Sequences 思维 + 组合数学

    传送门 文章目录 题意: 思路: 题意: 给你d,modd,modd,mod,让你求能构造出如下序列aaa的个数模modmodmod: 思路: 首先可以发现aaa的长度不能超过log2dlog_2dl ...

  4. 1450F The Struggling Contestant(贪心+思维)

    1450F The Struggling Contestant(贪心+思维) Codeforces Global Round 12 F. The Struggling Contestant 题面:Th ...

  5. 贪心/思维题 UVA 11292 The Dragon of Loowater

    题目传送门 1 /* 2 题意:n个头,m个士兵,问能否砍掉n个头 3 贪心/思维题:两个数组升序排序,用最弱的士兵砍掉当前的头 4 */ 5 #include <cstdio> 6 #i ...

  6. cf:B. Patchouli‘s Magical Talisman【数学贪心思维 + 奇偶分析】

    分析 给出一堆数 可以通过相加或除2让它们全部变成奇数 如果全奇数返回0 由于奇数 + 偶数 = 奇数 所以只要有一个奇数就能把偶数和它相加不停的变成奇数 所以只要存在奇数,就可以返回偶数的个数 否则 ...

  7. CodeForces - 1089L 贪心

    The kingdom of Lazyland is the home to nn idlers. These idlers are incredibly lazy and create many p ...

  8. 《C语言程序设计实践》————如何买玫瑰?(贪心思维)

    <C语言程序设计实践>----如何买玫瑰?(贪心思维) 要求:小慧过生日,小明要买玫瑰送她.每枝红玫瑰5元,满5支送1枝,满20枝送5枝.小明一共有n(n>10)元钱,最多能买到多少 ...

  9. codeforces数学1600day4[贪心数学公式推导CodeForces - 1151D ,思维CodeForces - 1085C,数论同余+组合计数 CodeForces - 1056B]

    A - Stas and the Queue at the Buffet CodeForces - 1151D 题目大意:就是给你n个人在排队,每个人都有一个ai值和bi值,每个人的不满意度就是f(i ...

最新文章

  1. 辞职前为什么挣扎_当您感到自己像开发人员一样挣扎时,为什么学得最多
  2. 做为一名IT新人,必了解程序员与产品经理的恩怨情仇
  3. 南通工学院计算机系97顾月,南通大学电气工程学院
  4. C 指针常量 和常量指针 指向常量的指针常量的使用
  5. 深入浅出HTTPS工作原理
  6. 图像条纹检测 python_机器视觉系统应用之—玻璃表面缺陷检测
  7. 设计模式笔记十五:命令模式
  8. RabbitMQ延迟消息队列实现定时任务完整代码示例
  9. Dead Pixel
  10. 物业计算机管理系统论文,小区物业管理系统设计毕业论文
  11. leelen可视对讲怎么接线_电子门铃怎么安装 电子对讲门铃安装方法【详细介绍】...
  12. 一对同居男女同一天的日记对比
  13. 成长笔记(个人心路历程)
  14. 【codecs】视频显示分辨率格式分析
  15. spoolsv.exe占用100%的解决之道
  16. 欧拉中的俯仰、横滚、偏航角
  17. DataStory·2017大数据商业创新论坛(上海站)圆满结束
  18. c语言文件wt,c语言,wt和rt中的t是什么意思
  19. String存放在堆中还是栈中?5年的Java照样说不清楚!
  20. uniapp打包h5_全局可视化装修商城上线,可打包APP

热门文章

  1. win32 socket的一个简单的例子 控制台
  2. 中望cad插件_中望软件与狄诺尼达成战略合作,打造交通行业全国产CAD解决方案...
  3. win10 hyper ubuntu18 共享文件夹
  4. HTML与CSS基础之伪元素(五)
  5. MySQL删除主键的操作方法
  6. 使用BaseAdapter实现复杂的ListView
  7. 外媒对中国量子计算机,中国超算世界第一,美国却研发出量子计算机,外媒:秒杀中国超算...
  8. stm32mp1安装linux系统,stm32mp1linux开发环境搭建(cortex a7)
  9. python右键没有idle编辑了_Python文件右键找不到IDLE打开项解决办法
  10. CYQ.Data 轻量数据访问层(八) 自定义数据表实现绑定常用的数据控件(中)