日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Dreamoon Likes Coloring CodeForces - 1330C(贪心+思维)

發布時間:2023/12/15 编程问答 44 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Dreamoon Likes Coloring CodeForces - 1330C(贪心+思维) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

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(贪心+思维)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。