mirror of
https://gitcode.com/Zengtudor/alg2025.git
synced 2025-09-04 01:01:43 +00:00
update
This commit is contained in:
parent
27ecded092
commit
ac99a0f6fb
@ -1,28 +1,27 @@
|
||||
#include <algorithm>
|
||||
#include <cstdint>
|
||||
#include <iostream>
|
||||
#include <istream>
|
||||
#include <numeric>
|
||||
#include <ostream>
|
||||
#include <vector>
|
||||
|
||||
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<ll> v(n);
|
||||
for(ll&i:v){
|
||||
std::cin>>i;
|
||||
std::vector<ll> 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<<dp[n]<<std::endl;
|
||||
_Exit(0);
|
||||
}
|
Loading…
Reference in New Issue
Block a user