Codeforces 461A Appleman and Toastman(贪心)

来源:互联网 发布:x软件下载 编辑:程序博客网 时间:2024/06/04 17:41

题目链接: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 = 3 * 1e5 + 5;int N, arr[maxn];int main () {    scanf("%d", &N);    ll sum = 0;    for (int i = 1; i <= N; i++) {        scanf("%d", &arr[i]);        sum += arr[i];    }    sort(arr + 1, arr + 1 + N);    ll ans = sum;    for (int i = 1; i < N; i++) {        ans += sum;        sum -= arr[i];    }    printf("%lld\n", ans);    return 0;}
0 0