1093C.md (2182B)
1 Source: https://codeforces.com/problemset/problem/1093/C 2 3 C. Mishka and the Last Exam 4 5 time limit per test 6 7 2 seconds 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 standard input 16 17 output 18 19 standard output 20 21 Mishka is trying really hard to avoid being kicked out of the university. In particular, he was doing absolutely nothing for the whole semester, miraculously passed some exams so that just one is left. 22 23 There were $n$ classes of that subject during the semester and on $i$-th class professor mentioned some non-negative integer $a_i$ to the students. It turned out, the exam was to tell the whole sequence back to the professor. 24 25 Sounds easy enough for those who attended every class, doesn't it? 26 27 Obviously Mishka didn't attend any classes. However, professor left some clues on the values of $a$ to help out students like Mishka: 28 29 * $a$ was sorted in non-decreasing order ($a_1 \le a_2 \le \dots \le a_n$); 30 * $n$ was even; 31 * the following sequence $b$, consisting of $\frac n 2$ elements, was formed and given out to students: $b_i = a_i + a_{n - i + 1}$. 32 33 Professor also mentioned that any sequence $a$, which produces sequence $b$ with the presented technique, will be acceptable. 34 35 Help Mishka to pass that last exam. Restore any sorted sequence $a$ of non-negative integers, which produces sequence $b$ with the presented technique. It is guaranteed that there exists at least one correct sequence $a$, which produces the given sequence $b$. 36 37 Input 38 39 The first line contains a single integer $n$ ($2 \le n \le 2 \cdot 10^5$) — the length of sequence $a$. $n$ is always even. 40 41 The second line contains $\frac n 2$ integers $b_1, b_2, \dots, b_{\frac n 2}$ ($0 \le b_i \le 10^{18}$) — sequence $b$, where $b_i = a_i + a_{n - i + 1}$. 42 43 It is guaranteed that there exists at least one correct sequence $a$, which produces the given sequence $b$. 44 45 Output 46 47 Print $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 10^{18}$) in a single line. 48 49 $a_1 \le a_2 \le \dots \le a_n$ should be satisfied. 50 51 $b_i = a_i + a_{n - i + 1}$ should be satisfied for all valid $i$. 52 53 Examples 54 55 Input 56 57 ``` 58 4 59 5 6 60 ``` 61 62 Output 63 64 ``` 65 2 3 3 3 66 ``` 67 68 Input 69 70 ``` 71 6 72 2 1 2 73 ``` 74 75 Output 76 77 ``` 78 0 0 1 1 1 2 79 ```