Codeforces Round 56-C. Mishka and the Last Exam(思维+贪心)

在一场特殊的考试中,Mishka必须回忆起教授在学期中提到的一系列非负整数。通过给定的线索,即序列b,其中b[i]=a[i]+a[n-i],并且序列a需按非递减顺序排列。本篇将介绍如何帮助Mishka通过构造满足条件的序列a来应对考试。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

4
5 6

output

Copy

2 3 3 3

input

Copy

6
2 1 2

output

Copy

0 0 1 1 1 2 

题解:

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

代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>

using namespace std;

int main()
{
	int n;
	cin>>n;
	long long int k;
	long long int a[200005];
	for(int t=0;t<n/2;t++)
	{
		cin>>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<n;t++)
	{
		cout<<a[t]<<" ";
	}
	
	
	return 0;
}

 

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

根据提供的引用内容,Codeforces Round 511 (Div. 1)是一个比赛的名称。然而,引用内容中没有提供这个比赛相关的具体信息或问题。因此,我无法回答关于Codeforces Round 511 (Div. 1)的问题。如果您有关于这个比赛的具体问题,请提供更多的信息,我将尽力回答。 #### 引用[.reference_title] - *1* [Codeforces Round 860 (Div. 2)题解](https://blog.csdn.net/qq_60653991/article/details/129802687)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [Codeforces Round 867 (Div. 3)(A题到E题)](https://blog.csdn.net/wdgkd/article/details/130370975)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [Codeforces Round 872 (Div. 2)(前三道](https://blog.csdn.net/qq_68286180/article/details/130570952)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值