#PU988. USACO 2020 January Contest, Bronze — Problem 2. Photoshoot

    ID: 1526 传统题 文件IO:photo 2000ms 256MiB 尝试: 0 已通过: 0 难度: 普及 上传者: 标签>USACO赛事:jan20来源:usaco.orgscoring:equal_test_cases枚举

USACO 2020 January Contest, Bronze — Problem 2. Photoshoot

USACO 2020 January Contest, Bronze — Problem 2. Photoshoot

题目描述

Farmer John is lining up his NN cows (2≤N≤1032\le N\le 10^3), numbered 1…N1\ldots N, for a photoshoot. FJ initially planned for the ii-th cow from the left to be the cow numbered ai,a_i, and wrote down the permutation a1,a2,…,aNa_1,a_2,\ldots,a_N on a sheet of paper. Unfortunately, that paper was recently stolen by Farmer Nhoj! Luckily, it might still be possible for FJ to recover the permutation that he originally wrote down. Before the sheet was stolen, Bessie recorded the sequence b1,b2,…,bN−1b_1,b_2,\ldots,b_{N-1} that satisfies bi=ai+ai+1b_i=a_i+a_{i+1} for each 1≤i<N.1\le i<N. Based on Bessie's information, help FJ restore the "lexicographically minimum" permutation aa that could have produced bb. A permutation xx is lexicographically smaller than a permutation yy if for some jj, xi=yix_i=y_i for all i<ji<j and xj<yjx_j<y_j (in other words, the two permutations are identical up to a certain point, at which xx is smaller than yy). It is guaranteed that at least one such aa exists.

输入格式

The first line of input contains a single integer N.N. The second line contains N−1N-1 space-separated integers b1,b2,…,bN−1.b_1,b_2,\ldots,b_{N-1}.

输出格式

A single line with NN space-separated integers a1,a2,…,aN.a_1,a_2,\ldots,a_{N}.

数据范围

Test cases 2-4 satisfy N≤8.N\le 8. Test cases 5-10 satisfy no additional constraints.

样例

样例 1

5
4 6 7 6
3 1 5 2 4
$a$ produces $b$ because $3+1=4$, $1+5=6$, $5+2=7$, and $2+4=6.$
Problem credits: Benjamin Qi and Chris Zhang