我是靠谱客的博主 温柔蚂蚁,这篇文章主要介绍http://codeforces.com/problemset/problem/160/A Twins,现在分享给大家,希望可以做个参考。

从大往小遍历的去加,直到拥有的大于剩下的价值。
老实说,当阅读理解做吧。

#include <iostream>
#include <string>
#define MAX 105
using namespace std;
int a[MAX];
int main() {
    freopen("a.txt", "r", stdin);
    freopen("b.txt", "w", stdout);
    int n, x, s = 0;
    cin >> n;
    for (int i = 0; i < n; ++i) cin >> x, a[x]++, s+= x;
    int sum = 0, ans = 0;
    for (int i = 100; i >= 1; --i) {
        while (a[i]) {
            if (sum > s) break;
            sum += i;
            ans++;
            s -= i;
            a[i]--;
        }
        if (sum > s) break;
    }
    cout << ans << endl;
    return 0;
}

最后

以上就是温柔蚂蚁最近收集整理的关于http://codeforces.com/problemset/problem/160/A Twins的全部内容,更多相关http://codeforces.com/problemset/problem/160/A内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(135)

评论列表共有 0 条评论

立即
投稿
返回
顶部