天天看點

Codeforces 461A Appleman and Toastman(貪心)

題目連結:Codeforces 461A Appleman and Toastman

題目大意:給定一個集合,每次由A将集合交個B,然後B計算集合中元素的總和,加到得分中,将集合還給A,然後A将集合随機分成兩個集合,然後逐個給B,B進行相同的操作,直到集合中元素個數為1時,A不拆分集合,而是直接舍棄。問說最大得分。

解題思路:貪心,每次從集合中剔除值最小的即可。

#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;
typedef long long ll;
const int maxn =  *  + ;

int N, arr[maxn];

int main () {
    scanf("%d", &N);

    ll sum = ;
    for (int i = ; i <= N; i++) {
        scanf("%d", &arr[i]);
        sum += arr[i];
    }

    sort(arr + , arr +  + N);

    ll ans = sum;
    for (int i = ; i < N; i++) {
        ans += sum;
        sum -= arr[i];
    }
    printf("%lld\n", ans);
    return ;
}