Codeforces 1330 C. Dreamoon Likes Coloring_88

题意:

一行上有 Codeforces 1330 C. Dreamoon Likes Coloring_88_02 个方格,给出每个颜色染色的长度 Codeforces 1330 C. Dreamoon Likes Coloring_88_03,可以选择从 Codeforces 1330 C. Dreamoon Likes Coloring_88_04

每个颜色染色的起点应不小于自己序次对应的方格。

无解的情况:

  • 若总染色长度小于 Codeforces 1330 C. Dreamoon Likes Coloring_88_05,最终一定会有方格没有颜色。
  • 若某个颜色的最大起点在前面的方格中,此时会覆盖先前至少一种颜色。

染色时的情况:
假设每个颜色互不覆盖能染的最大长度为 Codeforces 1330 C. Dreamoon Likes Coloring_88_06Codeforces 1330 C. Dreamoon Likes Coloring_88_07

Codeforces 1330 C. Dreamoon Likes Coloring_88_07 大于当前方格位置,说明如果从当前方格处开始染色最终一定会有空白的方格,此时至少要从 Codeforces 1330 C. Dreamoon Likes Coloring_88_07 处染色才能给每个方格染色。
Codeforces 1330 C. Dreamoon Likes Coloring_88_07

AC代码:

const int N = 1e5 + 10;
int a[N], ans[N];
int n, m;
int res, tmp, now;
ll sum;
int main()
{
sum = 0;
sdd(n, m);
rep(i, 1, m)
{
sd(a[i]);
sum += a[i];
}
if (sum < n)
{
puts("-1");
return 0;
}
rep(i, 1, m)
{
if (a[i] > (n - i + 1))
{
puts("-1");
return 0;
}
ans[i] = i;
}
now = n;
per(i, m, 1)
{
if (now - a[i] + 1 <= i)
{
ans[i] = i;
break;
}
ans[i] = now - a[i] + 1;
now -= a[i];
}
rep(i, 1, m)
printf("%d%c", ans[i], i == n ? '\n' : ' ');
return 0;
}