其实也很简单
直接考虑与前后取哪边不变
第一次左边取0,右边取最大
#include<bits/stdc++.h>
using namespace std;
#define int long long
inline int read(){
char ch=getchar();
int res=0;
while(!isdigit(ch))ch=getchar();
while(isdigit(ch))res=(res<<3)+(res<<1)+(ch^48),ch=getchar();
return res;
}
int n,k,a[200005];
int ans[200005];
signed main(){
k=n=read();
int p=n/2;
a[1]=read();
ans[1]=0,ans[k--]=a[1];
for(int i=2;i<=p;i++){
a[i]=read();
if(a[i]-ans[i-1]>ans[k+1]){
ans[k]=ans[k+1];
ans[i]=a[i]-ans[k];
k--;
}
else{
ans[i]=ans[i-1],ans[k]=a[i]-ans[i];
k--;
}
}
for(int i=1;i<=n;i++)cout<<ans[i]<<" ";
}