欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

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;
}