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

Codeforces 439B Devu, the Dumb Guy(贪心)

 
阅读更多

题目链接:Codeforces 439B Devu, the Dumb Guy


题目大意:Devu是个智商偏低的家伙,他现在要学习n门科目,每门科目有ci张图,一开始Devu掌握一张图的时间为x。但是每学完一个科目Devu的学习能力就会提高,掌握一张图的时间减少1(但是掌握一张图的时间最少为1,能力有限)。问你说他最少需要花多长的时间。


解题思路:因为科目数时不变的,所以一开始将图比较少得科目给Devu学习,后面图多的科目他的学习效率就比较高,贪心的思想。


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

using namespace std;
typedef long long ll;
const int N = 1e5 + 5;

ll n, x, c[N];

int main () {
    ll ans = 0;

    scanf("%lld%lld", &n, &x);
    for (int i = 0; i < n; i++)
        scanf("%lld", &c[i]);

    sort(c, c + n);

    for (int i = 0; i < n; i++) {
        ans += c[i] * x;

        if (x > 1)
            x--;
    }
    printf("%lld\n", ans);
    return 0;
}

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics