博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Codeforces Round 56-C. Mishka and the Last Exam(思维+贪心)
阅读量:5033 次
发布时间:2019-06-12

本文共 2477 字,大约阅读时间需要 8 分钟。

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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.

There were nn classes of that subject during the semester and on ii-th class professor mentioned some non-negative integer aiai to the students. It turned out, the exam was to tell the whole sequence back to the professor.

Sounds easy enough for those who attended every class, doesn't it?

Obviously Mishka didn't attend any classes. However, professor left some clues on the values of aa to help out students like Mishka:

  • aa was sorted in non-decreasing order (a1≤a2≤⋯≤ana1≤a2≤⋯≤an);
  • nn was even;
  • the following sequence bb, consisting of n2n2 elements, was formed and given out to students: bi=ai+an−i+1bi=ai+an−i+1.

Professor also mentioned that any sequence aa, which produces sequence bb with the presented technique, will be acceptable.

Help Mishka to pass that last exam. Restore any sorted sequence aa of non-negative integers, which produces sequence bb with the presented technique. It is guaranteed that there exists at least one correct sequence aa, which produces the given sequence bb.

Input

The first line contains a single integer nn (2≤n≤2⋅1052≤n≤2⋅105) — the length of sequence aa. nn is always even.

The second line contains n2n2 integers b1,b2,…,bn2b1,b2,…,bn2 (0≤bi≤10180≤bi≤1018) — sequence bb, where bi=ai+an−i+1bi=ai+an−i+1.

It is guaranteed that there exists at least one correct sequence aa, which produces the given sequence bb.

Output

Print nn integers a1,a2,…,ana1,a2,…,an (0≤ai≤10180≤ai≤1018) in a single line.

a1≤a2≤⋯≤ana1≤a2≤⋯≤an should be satisfied.

bi=ai+an−i+1bi=ai+an−i+1 should be satisfied for all valid ii.

Examples

input

Copy

45 6

output

Copy

2 3 3 3

input

Copy

62 1 2

output

Copy

0 0 1 1 1 2

题解:

题目大意是说b[i]=a[i]+a[n-i]的值,并且要保证是递增的,我们可以想,让左边的尽可能小,并且比右边的小,我们就可以去他左边的和右边较小的最大值即可,需要注意的是数据范围是 long long int型的

代码:

#include
#include
#include
#include
using namespace std;int main(){ int n; cin>>n; long long int k; long long int a[200005]; for(int t=0;t
>k; if(t==0) { a[0]=0; a[n-1]=k; } else { a[t]=max(a[t-1],min(a[n-t],k-a[n-t])); a[n-1-t]=k-a[t]; } } for(int t=0;t

 

转载于:https://www.cnblogs.com/Staceyacm/p/10781919.html

你可能感兴趣的文章
Leetcode总结之Backtracking
查看>>
Android开发学习之路-图片颜色获取器开发(1)
查看>>
StackExchange.Redis 官方文档(一) Basics
查看>>
nupkg 之破解 nodejs+electron-packager 打包exe的解包
查看>>
Objective-C 使用 C++类
查看>>
浅谈之高级查询over(partition by)
查看>>
Notes: CRM Analytics–BI from a CRM perspective (2)
查看>>
graphite custom functions
查看>>
列出所有的属性键
查看>>
js获取请求地址后面带的参数
查看>>
设计模式のCompositePattern(组合模式)----结构模式
查看>>
二进制集合枚举子集
查看>>
磁盘管理
查看>>
SAS学习经验总结分享:篇二—input语句
查看>>
UIImage与UIColor互转
查看>>
RotateAnimation详解
查看>>
系统管理玩玩Windows Azure
查看>>
c#匿名方法
查看>>
如何判断链表是否有环
查看>>
【小程序】缓存
查看>>