Dreamoon Likes Coloring
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
#include <bits/stdc++.h>#define ll long long
using namespace std;
const int N = 1e5 + 10;
int ans[N], l[N], n, m;
ll sum;int main() {cin >> n >> m;for (int i = 1; i <= m; i++)scanf("%d", &l[i]), sum += l[i];if (sum < n) {puts("-1");return 0;}for (int i = 1; i <= m; i++)if (n - l[i] + 1 < i) {puts("-1");return 0;}ll rec = sum - n;int now = 1;for (int i = 1; i <= m; i++) {ans[i] = now;int res = min(rec, 1ll * l[i] - 1);rec -= res;now = now + l[i] - res;}for (int i = 1; i <= m; i++)printf("%d ", ans[i]);return 0;
}
Dreamoon Likes Coloring相关推荐
- Dreamoon Likes Coloring CodeForces - 1330C(贪心+思维)
Dreamoon likes coloring cells very much. There is a row of n cells. Initially, all cells are empty ( ...
- Codeforces Round #631 (Div. 2) C. Dreamoon Likes Coloring 构造
传送门 文章目录 题意: 思路: 题意: 思路: 针灸思维不行,数据结构来凑呗. 一开始做的时候想简单了,一直wawawa,后来想到了hackhackhack样例,开始换思路构造,结果死活想不到O(m ...
- Dreamoon Likes Sequences CodeForces - 1330D(组合数学+位运算)
Dreamoon likes sequences very much. So he created a problem about the sequence that you can't find i ...
- Codeforces Round #631 (Div. 2) D. Dreamoon Likes Sequences 思维 + 组合数学
传送门 文章目录 题意: 思路: 题意: 给你d,modd,modd,mod,让你求能构造出如下序列aaa的个数模modmodmod: 思路: 首先可以发现aaa的长度不能超过log2dlog_2dl ...
- CodeForces - 1330D Dreamoon Likes Sequences(组合数学)
题目链接:点击查看 题目大意:给出一个限制 d 与模数 mod ,求出可以构造出的满足条件的数组 a 的个数,需要满足以下条件: 数组 a 的长度大于等于 1 数组 a 严格递增 数组 a 的最小值大 ...
- D. Dreamoon Likes Sequences(异或)
Problem - 1330D - Codeforces 题意: 给你两个整数d,m,找出数组a的数量,满足以下约束. a的长度为n,n≥1 1≤a1<a2<⋯<an≤d 定义长度为 ...
- szu cf集训Codeforces Round #631 (Div. 2)A ~ D[贪心,数据结构,思维,dp]
A. Dreamoon and Ranking Collection 题意:题意不太好理解.简单来讲就是,给出一组数,能从1最多数到几,不够的用数来填,最多填x次.思路:代码很简单-先出现过的地方肯定 ...
- 【11.9】Codeforces 刷题
DP\text{DP}DP : B. Yaroslav and Two Strings 题意: 如果两个只包含数字且长度为 n(1≤n≤105)n(1\leq n\leq 10^5)n(1≤n≤105 ...
- android xlintdeprecation 重新编译,天博体育官网-官网首页
PC Flutter 裁剪布局之 ClipRect.ClipRRect.ClipOval.ClipPath.CustomClipper. 斯坦福大学公开课机器学习:Neural network-mod ...
- Codeforces Round #272 (Div. 2)
链接 : http://codeforces.com/contest/476 D题yy,ABC水 A. Dreamoon and Stairs time limit per test 1 second ...
最新文章
- VS2010 自定义用户控件未出现在工具箱的解决方案
- Qt窗口部件与布局之二:布局管理
- 浏览器为什么会有兼容性问题
- 高性能SQLServer通用分页存储过程
- Widget开发中遇到的坑
- uni-app目录结构介绍
- python读数据小数点_将excel数据读入pandas dataframe,精确到小数点后20位
- Linux scp 使用详解
- 查看编译class文件时,使用的JDK版本(只能查看到大版本)
- Spring Boot 集成undertow作为web容器分析
- Android事件分发机制综述
- 阿里云商标注册申请智能、顾问和安心区别及选择攻略
- 中小型企业应该选择什么样的OA系统?
- php导出数据库为excel文件,phpexcel导出数据库成excel文件
- 没有免费午餐定理No Free Lunch Theorem
- mysql mmm 测试_mysql-mmm有关mmm_control 参数测试
- 计算机三级网络技术最全知识点总结一
- Android百度地图显示附近的位置
- m4r格式转换器免费版 V3.0
- safari下载文件_如何更改Safari下载文件夹的位置