bdfz_2024_summer/day9/P9127/P9127.cpp
2024-08-12 17:03:07 +08:00

60 lines
1.1 KiB
C++

#include<bits/stdc++.h>
using namespace std;
#define int long long
struct Node{
int l,r,s;
};
const int MAX_N = 505;
int n,pn=0;
int a[MAX_N];
int ans[MAX_N];
int changed=0;
Node node[MAX_N*MAX_N];
int readint();
signed main(signed argc,char *argv[]){
n=readint();
for(int i=1;i<=n;i++){
a[i]=readint();
}
for(int i=1;i<=n;i++){
int cnt=0;
for(int j=i;j<=n;j++){
cnt+=a[j];
node[++pn] = {
i,j,cnt
};
}
}
sort(node+1,node+1+pn,[](Node a,Node b)->bool{
return a.s<b.s;
});
int pmincmplast = INT_MAX;
for(int i=1;i<pn;i++){
for(int j=node[i].l;j<=node[i].r;j++){
if (ans[j]==0) {
abs(node[i].s-node[i+1].s);
}else{
ans[j]=min(abs(node[i].s-node[i+1].s),ans[j]);
}
}
}
for(int i=1;i<=n;i++){
cout<<ans[i]<<endl;
}
}
int readint(){
int x=0,w=1;
char ch=0;
while(!isdigit(ch)){
if(ch=='-')w=-1;
ch=getchar();
}
while(isdigit(ch)){
x=x*10+(ch-'0');
ch=getchar();
}
return x*w;
}