This commit is contained in:
Zengtudor 2024-10-20 16:16:23 +08:00
parent 1de78a12e0
commit 2f6eb0bc61

47
src/P9127/P9127.cpp Normal file
View File

@ -0,0 +1,47 @@
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <limits>
using ll = long long;
const ll max_n = 500+5;
ll n, arr[max_n], pre[max_n];
struct Sec{
ll start,end,sum;
bool is_have(const ll &n)const noexcept{
return start<=n && n<=end;
}
}secs[max_n*max_n];
ll secs_size{1};
const ll buf_size {1024*1024*1024};
char buf[buf_size];
int main(){
std::cin.rdbuf()->pubsetbuf(buf, buf_size);
std::cin>>n;
for(ll i{1};i<=n;i++){
std::cin>>arr[i];
pre[i]=pre[i-1]+arr[i];
}
for(ll i{1};i<=n;i++){
for(ll j{i};j<=n;j++){
secs[secs_size++] = {i,j,pre[j]-pre[i-1]};
}
}
std::sort(secs+1,secs+secs_size,[](const Sec &a,const Sec &b)->bool{
return a.sum<b.sum;
});
for(ll i{1};i<=n;i++){
ll min{std::numeric_limits<ll>::max()};
for(ll j{2};j<=secs_size;j++){
if(secs[j-1].is_have(i) != secs[j].is_have(i)){
min = std::min(min,std::abs(secs[j].sum-secs[j-1].sum));
}
}
std::cout<<min<<'\n';
}
}