本文主要是介绍Codeforces Round #631 (Div. 2) - Thanks, Denis aramis Shitov! C. Dreamoon Likes Coloring(贪心+思维),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
题目链接
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+5;
int p[maxn];
int ans[maxn];
int main()
{
int n,m;ll sum=0;scanf("%d %d",&n,&m);int cnt=n;for(int i=1;i<=m;++i) scanf("%lld",&p[i]),sum+=p[i],ans[i]=i;if(sum<n) {printf("-1\n");return 0;}
for(int i=1;i<=m;++i){if(p[i] > (n - i + 1)) {printf("-1\n");return 0;}}for(int i=m;i>=1;--i){if(cnt - p[i] + 1 <= i){ans[i] = i;break;}ans[i] = cnt - p[i] + 1;cnt -= p[i];}for(int i=1;i<=m;++i) cout<<ans[i]<<" ";
}
这篇关于Codeforces Round #631 (Div. 2) - Thanks, Denis aramis Shitov! C. Dreamoon Likes Coloring(贪心+思维)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!