CF1500F.Cupboards Jumps

NOI/NOI+/CTSC

通过率:0%

时间限制:6.00s

内存限制:512MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

In the house where Krosh used to live, he had nn cupboards standing in a line, the ii-th cupboard had the height of hih_i. Krosh moved recently, but he wasn't able to move the cupboards with him. Now he wants to buy nn new cupboards so that they look as similar to old ones as possible.

Krosh does not remember the exact heights of the cupboards, but for every three consecutive cupboards he remembers the height difference between the tallest and the shortest of them. In other words, if the cupboards' heights were h1,h2,…,hnh_1, h_2, \ldots, h_n, then Krosh remembers the values wi=max⁡(hi,hi+1,hi+2)−min⁡(hi,hi+1,hi+2)w_i = \max(h_{i}, h_{i + 1}, h_{i + 2}) - \min(h_{i}, h_{i + 1}, h_{i + 2}) for all 1≤i≤n−21 \leq i \leq n - 2.

Krosh wants to buy such nn cupboards that all the values wiw_i remain the same. Help him determine the required cupboards' heights, or determine that he remembers something incorrectly and there is no suitable sequence of heights.

在克罗什曾经居住的房子里,他有 nn 个并排摆放的橱柜,第 ii 个橱柜的高度为 hih_i。克罗什最近搬了家,但没能把橱柜一起带走。现在他想购买 nn 个新橱柜,使其外观尽可能接近原来的橱柜。

克罗什记不清橱柜的确切高度,但他记得每三个连续橱柜中最高者与最低者之间的高度差。换言之,若原橱柜高度序列为 h1,h2,…,hnh_1, h_2, \ldots, h_n,则克罗什记住了所有 1≤i≤n−21 \leq i \leq n - 2 对应的值

wi=max⁡(hi,hi+1,hi+2)−min⁡(hi,hi+1,hi+2)。w_i = \max(h_{i}, h_{i + 1}, h_{i + 2}) - \min(h_{i}, h_{i + 1}, h_{i + 2})。

克罗什希望购买的 nn 个新橱柜能保持所有 wiw_i 的值不变。请帮助他确定满足条件的橱柜高度序列;若不存在这样的高度序列(即克罗什的记忆有误),则判定无解。

输入格式

The first line contains two integers nn and CC (3≤n≤1063 \leq n \leq 10^6, 0≤C≤10120 \leq C \leq 10^{12}) — the number of cupboards and the limit on possible wiw_i.

The second line contains n−2n - 2 integers w1,w2,…,wn−2w_1, w_2, \ldots, w_{n - 2} (0≤wi≤C0 \leq w_i \leq C) — the values defined in the statement.

第一行包含两个整数 nn 和 CC(3≤n≤1063 \leq n \leq 10^6,0≤C≤10120 \leq C \leq 10^{12})—— 分别表示橱柜的数量以及 wiw_i 的上限。

第二行包含 n−2n - 2 个整数 w1,w2,…,wn−2w_1, w_2, \ldots, w_{n - 2}(0≤wi≤C0 \leq w_i \leq C)—— 即题目描述中定义的数值。

输出格式

If there is no suitable sequence of nn cupboards, print "NO".

Otherwise print "YES" in the first line, then in the second line print nn integers h1′,h2′,…,hn′h'_1, h'_2, \ldots, h'_n (0≤hi′≤10180 \le h'_i \le 10^{18}) — the heights of the cupboards to buy, from left to right.

We can show that if there is a solution, there is also a solution satisfying the constraints on heights.

If there are multiple answers, print any.

如果不存在满足条件的 nn 个橱柜序列,则输出 "NO"。

否则,第一行输出 "YES",第二行输出 nn 个整数 h1′,h2′,…,hn′h'_1, h'_2, \ldots, h'_n(0≤hi′≤10180 \le h'_i \le 10^{18}),表示从左到右需要购买的橱柜高度。

可以证明:若存在解,则必存在一个满足高度约束条件的解。

若存在多个答案,输出任意一个即可。

输入输出样例

  • 输入#1

    7 20
    4 8 12 16 20

    输出#1

    YES
    4 8 8 16 20 4 0
  • 输入#2

    11 10
    5 7 2 3 4 5 2 1 8

    输出#2

    YES
    1 1 6 8 6 5 2 0 0 1 8
  • 输入#3

    6 9
    1 6 9 0

    输出#3

    NO

说明/提示

Consider the first example:

  • w1=max⁡(4,8,8)−min⁡(4,8,8)=8−4=4w_1 = \max(4, 8, 8) - \min(4, 8, 8) = 8 - 4 = 4
  • w2=max⁡(8,8,16)−min⁡(8,8,16)=16−8=8w_2 = \max(8, 8, 16) - \min(8, 8, 16) = 16 - 8 = 8
  • w3=max⁡(8,16,20)−min⁡(8,16,20)=20−8=12w_3 = \max(8, 16, 20) - \min(8, 16, 20) = 20 - 8 = 12
  • w4=max⁡(16,20,4)−min⁡(16,20,4)=20−4=16w_4 = \max(16, 20, 4) - \min(16, 20, 4) = 20 - 4 = 16
  • w5=max⁡(20,4,0)−min⁡(20,4,0)=20−0=20w_5 = \max(20, 4, 0) - \min(20, 4, 0) = 20 - 0 = 20

There are other possible solutions, for example, the following: 0,1,4,9,16,25,360, 1, 4, 9, 16, 25, 36.

考虑第一个例子:

  • w1=max⁡(4,8,8)−min⁡(4,8,8)=8−4=4w_1 = \max(4, 8, 8) - \min(4, 8, 8) = 8 - 4 = 4
  • w2=max⁡(8,8,16)−min⁡(8,8,16)=16−8=8w_2 = \max(8, 8, 16) - \min(8, 8, 16) = 16 - 8 = 8
  • w3=max⁡(8,16,20)−min⁡(8,16,20)=20−8=12w_3 = \max(8, 16, 20) - \min(8, 16, 20) = 20 - 8 = 12
  • w4=max⁡(16,20,4)−min⁡(16,20,4)=20−4=16w_4 = \max(16, 20, 4) - \min(16, 20, 4) = 20 - 4 = 16
  • w5=max⁡(20,4,0)−min⁡(20,4,0)=20−0=20w_5 = \max(20, 4, 0) - \min(20, 4, 0) = 20 - 0 = 20

还有其他可能的解,例如以下序列:0,1,4,9,16,25,360, 1, 4, 9, 16, 25, 36。

输入解题思路,AI测评打分。不知道怎么写?

首页