0% found this document useful (0 votes)
27 views

N I H N: Input

Krosh wants to buy new cupboards that match the height differences of groups of 3 of his old cupboards. He remembers the height difference between the tallest and shortest cupboard in groups of 3 old cupboards but not their individual heights. The question is to determine if there is a possible set of new cupboard heights that matches Krosh's remembered height differences, and if so to provide that set of heights.

Uploaded by

Md.Amdad Hossain
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views

N I H N: Input

Krosh wants to buy new cupboards that match the height differences of groups of 3 of his old cupboards. He remembers the height difference between the tallest and shortest cupboard in groups of 3 old cupboards but not their individual heights. The question is to determine if there is a possible set of new cupboard heights that matches Krosh's remembered height differences, and if so to provide that set of heights.

Uploaded by

Md.Amdad Hossain
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

In the house where Krosh used to live, he had 

nn cupboards standing in a line, the ii-th cupboard


had the height of hihi. 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,…,hnh1,h2,…,hn, then Krosh remembers the
values wi=max(hi,hi+1,hi+2)−min(hi,hi+1,hi+2)wi=max(hi,hi+1,hi+2)−min(hi,hi+1,hi+2) for
all 1≤i≤n−21≤i≤n−2.
Krosh wants to buy such nn cupboards that all the values wiwi 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.
Input
The first line contains two integers nn and CC (3≤n≤1063≤n≤106, 0≤C≤10120≤C≤1012) — the
number of cupboards and the limit on possible wiwi.
The second line contains n−2n−2 integers w1,w2,…,wn−2w1,w2,…,wn−2 (0≤wi≤C0≤wi≤C) —
the values defined in the statement.
Output
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 h′1,h′2,…,h′nh1′,h2′,
…,hn′ (0≤h′i≤10180≤hi′≤1018) — 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.

You might also like