CF1326B.Maximums

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Alicia has an array, a1,a2,…,ana_1, a_2, \ldots, a_n, of non-negative integers. For each 1≤i≤n1 \leq i \leq n, she has found a non-negative integer xi=max(0,a1,…,ai−1)x_i = max(0, a_1, \ldots, a_{i-1}). Note that for i=1i=1, xi=0x_i = 0.

For example, if Alicia had the array a=0,1,2,0,3a = {0, 1, 2, 0, 3}, then x=0,0,1,2,2x = {0, 0, 1, 2, 2}.

Then, she calculated an array, b1,b2,…,bnb_1, b_2, \ldots, b_n: bi=ai−xib_i = a_i - x_i.

For example, if Alicia had the array a=0,1,2,0,3a = {0, 1, 2, 0, 3}, b=0−0,1−0,2−1,0−2,3−2=0,1,1,−2,1b = {0-0, 1-0, 2-1, 0-2, 3-2} = {0, 1, 1, -2, 1}.

Alicia gives you the values b1,b2,…,bnb_1, b_2, \ldots, b_n and asks you to restore the values a1,a2,…,ana_1, a_2, \ldots, a_n. Can you help her solve the problem?

艾丽西亚有一个由非负整数构成的数组 a1,a2,…,ana_1, a_2, \ldots, a_n。对每个 1≤i≤n1 \leq i \leq n,她计算出一个非负整数 xi=max⁡(0,a1,…,ai−1)x_i = \max(0, a_1, \ldots, a_{i-1})。注意:当 i=1i=1 时,xi=0x_i = 0。

例如,若艾丽西亚的数组为 a={0,1,2,0,3}a = \{0, 1, 2, 0, 3\},则 x={0,0,1,2,2}x = \{0, 0, 1, 2, 2\}。

接着,她计算出另一个数组 b1,b2,…,bnb_1, b_2, \ldots, b_n:bi=ai−xib_i = a_i - x_i。

例如,若艾丽西亚的数组为 a={0,1,2,0,3}a = \{0, 1, 2, 0, 3\},则
b={0−0, 1−0, 2−1, 0−2, 3−2}={0, 1, 1, −2, 1}b = \{0-0,\ 1-0,\ 2-1,\ 0-2,\ 3-2\} = \{0,\ 1,\ 1,\ -2,\ 1\}。

艾丽西亚将 b1,b2,…,bnb_1, b_2, \ldots, b_n 的值给你,并请你还原出原始数组 a1,a2,…,ana_1, a_2, \ldots, a_n。你能帮她解决这个问题吗?

输入格式

The first line contains one integer nn (3≤n≤200 0003 \leq n \leq 200\,000) – the number of elements in Alicia's array.

The next line contains nn integers, b1,b2,…,bnb_1, b_2, \ldots, b_n (−109≤bi≤109-10^9 \leq b_i \leq 10^9).

It is guaranteed that for the given array bb there is a solution a1,a2,…,ana_1, a_2, \ldots, a_n, for all elements of which the following is true: 0≤ai≤1090 \leq a_i \leq 10^9.

第一行包含一个整数 nn(3≤n≤200 0003 \leq n \leq 200\,000)——表示 Alicia 数组中的元素个数。

下一行包含 nn 个整数 b1,b2,…,bnb_1, b_2, \ldots, b_n(−109≤bi≤109-10^9 \leq b_i \leq 10^9)。

保证对于给定的数组 bb,存在一个解 a1,a2,…,ana_1, a_2, \ldots, a_n,使得所有元素均满足:0≤ai≤1090 \leq a_i \leq 10^9。

输出格式

Print nn integers, a1,a2,…,ana_1, a_2, \ldots, a_n (0≤ai≤1090 \leq a_i \leq 10^9), such that if you calculate xx according to the statement, b1b_1 will be equal to a1−x1a_1 - x_1, b2b_2 will be equal to a2−x2a_2 - x_2, ..., and bnb_n will be equal to an−xna_n - x_n.

It is guaranteed that there exists at least one solution for the given tests. It can be shown that the solution is unique.

输出 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(其中 0≤ai≤1090 \leq a_i \leq 10^9),使得根据题面描述计算出 xx 后,满足 b1=a1−x1b_1 = a_1 - x_1,b2=a2−x2b_2 = a_2 - x_2,……,bn=an−xnb_n = a_n - x_n。

保证给定的测试数据至少存在一个解。可以证明该解是唯一的。

输入输出样例

  • 输入#1

    5
    0 1 1 -2 1

    输出#1

    0 1 2 0 3
  • 输入#2

    3
    1000 999999000 -1000000000

    输出#2

    1000 1000000000 0
  • 输入#3

    5
    2 1 2 2 3

    输出#3

    2 3 5 7 10

说明/提示

The first test was described in the problem statement.

In the second test, if Alicia had an array a=1000,1000000000,0a = {1000, 1000000000, 0}, then x=0,1000,1000000000x = {0, 1000, 1000000000} and b=1000−0,1000000000−1000,0−1000000000=1000,999999000,−1000000000b = {1000-0, 1000000000-1000, 0-1000000000} = {1000, 999999000, -1000000000}.

第一个测试用例已在题目描述中给出。

在第二个测试用例中,若 Alicia 拥有数组 a=1000,1000000000,0a = {1000, 1000000000, 0},则 x=0,1000,1000000000x = {0, 1000, 1000000000},且 b=1000−0,1000000000−1000,0−1000000000=1000,999999000,−1000000000b = {1000-0, 1000000000-1000, 0-1000000000} = {1000, 999999000, -1000000000}。

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

首页