`
阿尔萨斯
  • 浏览: 4168301 次
社区版块
存档分类
最新评论

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 = 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;
}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics