From 2f6eb0bc61b0e4a880e43e8c5830503bf2b28b4c Mon Sep 17 00:00:00 2001 From: Zengtudor Date: Sun, 20 Oct 2024 16:16:23 +0800 Subject: [PATCH] update --- src/P9127/P9127.cpp | 47 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 src/P9127/P9127.cpp 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<