From ac99a0f6fba7a540d733cfb0bbb6b664d0240439 Mon Sep 17 00:00:00 2001 From: Zengtudor Date: Tue, 26 Aug 2025 13:48:30 +0800 Subject: [PATCH] update --- src/8/26/P5124.cpp | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/src/8/26/P5124.cpp b/src/8/26/P5124.cpp index 7df1f5e..27b9bdf 100644 --- a/src/8/26/P5124.cpp +++ b/src/8/26/P5124.cpp @@ -1,28 +1,27 @@ #include +#include #include #include -#include +#include #include - using ll = int64_t; -#define pv(v)do{std::cout<<#v<<": "<<(v)<<"\n";}while(0) - int main(){ std::iostream::sync_with_stdio(false); std::cin.tie(nullptr); - ll n,k; std::cin>>n>>k; - std::vector v(n); - for(ll&i:v){ - std::cin>>i; + std::vector v(n+1),dp(n+1); + for(ll i=1;i<=n;i++){ + std::cin>>v[i]; } - std::sort(v.begin(),v.end()); - ll teams=n/k,last=n%k; - ll teamssum = std::accumulate(v.rbegin(),v.rbegin()+teams,0); - // pv(teams); - // pv(teamssum); - // pv(last); - std::cout<<(last * (*(v.rbegin()+teams)) + teamssum*k)<<"\n"; + for(ll i=1;i<=n;i++){ + ll max=0; + for(ll len=1;len<=k&&len<=i;len++){ + max=std::max(max,v[i-len+1]); + dp[i]=std::max(dp[i],max*len+dp[i-len]); + } + } + std::cout<