BZOJ 2697 Watery Problem
程序员文章站
2022-07-12 15:52:55
...
https://www.lydsy.com/JudgeOnline/problem.php?id=2697
A Watery Problem
Just using the Greedy Algorithm to solve it
code of AC:
#include<bits/stdc++.h>
using namespace std;
int A[2000];
int main(){
int n,k;
cin>>n>>k;
for(int i=1;i<=k;++i){
cin>>A[i];
}
sort(A+1,A+1+k);
int ans=0;
for(int i=k;i>=1&&n>=2;--i){
ans+=(n-1)*A[i];
n-=2;
}
cout<<ans<<endl;
}