版权声明:欢迎转载欢迎评论! https://blog.csdn.net/rabbit_ZAR/article/details/85175132
思路:
其实,这就是个贪心…
把a[i]尽量取小,a[n-i+1]取大就好了。
代码:
#include<bits/stdc++.h>
using namespace std;
#define read(t) scanf("%d",&t)
#define readll(t) scanf("%lld",&t)
#define maxn 200000
#define ll long long
int n;
ll a[maxn+5],b[maxn+5];
int main() {
read(n);
for(int i=1;i<=n/2;i++) readll(b[i]);
a[n+1]=(1LL<<62);
for(int i=1;i<=n/2;i++) {
a[i]=a[i-1];
a[n-i+1]=b[i]-a[i];
if(a[n-i+1]>a[n-i+2]) {
a[n-i+1]=a[n-i+2];
a[i]=b[i]-a[n-i+1];
}
}
for(int i=1;i<=n;i++) printf("%lld ",a[i]);
return 0;
}