Hard to Miss
View as PDFMatt is watching the shooting finals.
There are marksmen standing next to each other along the shooting range, numbered from
to
from left to right. A formation of
targets moves across the range from left to
right, with the same spacing as the marksmen. Hitting target
adds
points to a
marksman's score.
Initially, target is directly in front of marksman
. Each second, every marksman with a
target directly in front of them fires exactly once, and all shots are simultaneous. Every shot
hits, and targets remain in the formation after being hit. If marksman
has fired, the round
ends; otherwise, the formation moves one position to the right before the next second.
Formally, let be the score of marksman
, initially
for every
.
For each second
in order, the following happens:
Unfortunately, Matt is short-sighted and cannot see the targets. He can only see the final
scoreboard , where
is the score of marksman
.
Find a possible number of targets and their point values
that
produce the given final scoreboard.
If there are several valid formations, output any of them. If none exists, output -1.
Input
The first line contains an integer (
), the number of marksmen.
The second line contains integers
(
),
their final scores.
Output
If no valid formation exists, print -1 on a single line.
Otherwise, print an integer (
), the number of targets, on the first line.
On the second line, print
space-separated integers
(
), the targets' point values in their initial left-to-right order.
Example 1
Input
3
2 5 3
Output
2
2 3
Explanation
The formation has targets, worth
and
points.
- Second
: marksman
hits target
for
points, marksman
hits target
for
points. The scoreboard reads
.
- Second
: the formation moves right by one position, so marksman
hits target
for
points and marksman
hits target
for
points. The scoreboard reads
. Since the rightmost marksman has hit a target, the round ends.
Example 2
Input
5
2 7 10 8 3
Output
4
2 5 5 3
Explanation
The formation has targets, worth
,
,
and
points.
- Second
: the targets are in front of marksmen
to
, and the scoreboard reads
.
- Second
: the formation has moved right by one position, so the targets are in front of marksmen
to
. After they shoot, the scoreboard reads
. Since the rightmost marksman has hit a target, the round ends.
Another formation that is consistent with this scoreboard is , which will also be accepted.
Example 3
Input
1
7
Output
1
7
Explanation
There is only one marksman, so the formation has one target and the round ends
after one shot. The target must be worth exactly points.
Comments