diff --git a/src/P9127/P9127.cpp b/src/P9127/P9127.cpp new file mode 100644 index 0000000..f79b42b --- /dev/null +++ b/src/P9127/P9127.cpp @@ -0,0 +1,47 @@ + +#include +#include +#include +#include + +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::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<