Codeforce 712A Memory and Crow

简介: A. Memory and Crow time limit per test:2 seconds memory limit per test:256 megabytes input:standard input output:standard output There are n integers b1, b2, .
A. Memory and Crow
time limit per test:2 seconds
memory limit per test:256 megabytes
input:standard input
output:standard output

There are n integers b1, b2, ..., bn written in a row. For all i from 1 to n, values ai are defined by the crows performing the following procedure:

  • The crow sets ai initially 0.
  • The crow then adds bi to ai, subtracts bi + 1, adds the bi + 2 number, and so on until the n'th number. Thus, ai = bi - bi + 1 + bi + 2 - bi + 3....

Memory gives you the values a1, a2, ..., an, and he now wants you to find the initial numbers b1, b2, ..., bn written in the row? Can you do it?

Input

The first line of the input contains a single integer n (2 ≤ n ≤ 100 000) — the number of integers written in the row.

The next line contains n, the i'th of which is ai ( - 109 ≤ ai ≤ 109) — the value of the i'th number.

Output

Print n integers corresponding to the sequence b1, b2, ..., bn. It's guaranteed that the answer is unique and fits in 32-bit integer type.

Examples
Input
5
6 -4 8 -2 3
Output
2 4 6 1 3 
Input
5
3 -2 -1 5 6
Output
1 -3 4 11 6 
Note

In the first sample test, the crows report the numbers 6, - 4, 8, - 2, and 3 when he starts at indices 1, 2, 3, 4 and 5 respectively. It is easy to check that the sequence 2 4 6 1 3 satisfies the reports. For example, 6 = 2 - 4 + 6 - 1 + 3, and  - 4 = 4 - 6 + 1 - 3.

In the second sample test, the sequence 1,  - 3, 4, 11, 6 satisfies the reports. For example, 5 = 11 - 6 and 6 = 6.

解题思路:

【题意】
有n个数b1, b2, ..., bn

a1, a2, ..., an是通过等式ai = bi - bi + 1 + bi + 2 - bi + 3....(±)bn得到的

现给你a1, a2, ..., an这n个数,问b1, b2, ..., bn是多少
【类型】
公式推导
【分析】

由此可见,数组b中的第i项等于数组a中的第i项与第i+1项之和

特别地,数组b中的第n项等于数组a中的第n项


【时间复杂度&&优化】
O(n)

题目链接→Codeforces Problem 712A Memory and Crow

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 int main()
 4 {
 5     int n,a,b;
 6     while(cin>>n)
 7     {
 8         for(int i=1;i<=n;i++)
 9         {
10             cin>>a;
11             if(i>1)
12                 cout<<a+b<<" ";
13             b=a;
14         }
15         cout<<a<<endl;
16     }
17     return 0;
18 }

 

目录
相关文章
|
2月前
|
Android开发
Out of memory on a 11111-byte allocation
Out of memory on a 11111-byte allocation
27 1
|
2月前
|
监控 数据处理 算法框架/工具
Allocation of 179437568 exceeds 10% of free system memory.
本文讨论了在Python编程中遇到的"Allocation of XXXX exceeds 10% of free system memory"错误,并提供了几种解决方法,包括调整代码逻辑以减少内存分配和更改批量大小。
|
5月前
PGA memory operation
PGA memory operation
52 1
|
5月前
|
安全 数据处理 C#
深入理解C#中的Span<T>和Memory<T>
【1月更文挑战第8天】本文旨在探讨C#中引入的两个重要类型:Span<T>和Memory<T>。它们为开发者提供了一种高效且安全的方式来处理内存中的数据。文章首先介绍这两个类型的基本概念和用途,接着深入分析它们的工作原理和适用场景,并通过代码示例展示如何在实际应用中使用它们。
什么是 ABAP 编程语言的 Used Memory 和 Allocated Memory
什么是 ABAP 编程语言的 Used Memory 和 Allocated Memory
|
Docker 容器
解决Native memory allocation (mmap) failed to map 2060255232 bytes for committing reserved memory.
解决Native memory allocation (mmap) failed to map 2060255232 bytes for committing reserved memory.
1121 0
ZCMU - 2018: Memory leak
ZCMU - 2018: Memory leak
118 0