Codeforces Round #251 (Div. 2) 439B Devu, the Dumb Guy(贪心)
来源:互联网 发布:淘宝意想星球 编辑:程序博客网 时间:2024/05/16 09:56
给出n个章节,每个章节需要的时间不同,每学一个章节,时间会减少1,但不会为0,问你最少时间是多少。
排序后加起来即可。
AC代码:
#include "iostream"#include "cstdio"#include "cstring"#include "algorithm"using namespace std;typedef long long ll;const int maxn = 1e5 + 5;int main(int argc, char const *argv[]){int n;ll x;while(scanf("%d%lld", &n, &x) != EOF) {ll c[maxn];for(int i = 0; i < n; ++i)scanf("%lld", &c[i]);sort(c, c + n);ll ans = 0;for(int i = 0; i < n; ++i) {if(x == 1) ans += c[i];else {ans += (c[i] * x);x--;}}printf("%lld\n", ans);}return 0;}
1 0
- Codeforces Round #251 (Div. 2) 439B Devu, the Dumb Guy(贪心)
- Codeforces Round #251(Div. 2) 439B. Devu, the Dumb Guy 贪心
- Codeforces 439B Devu, the Dumb Guy(贪心)
- Codeforces 439B Devu, the Dumb Guy
- Codeforces 439 B. Devu, the Dumb Guy
- CodeForces 439B Devu, the Dumb Guy
- CodeForces 439B Devu, the Dumb Guy
- Codeforces 439B Devu, the Dumb Guy
- B. Devu, the Dumb Guy
- B. Devu, the Dumb Guy
- Devu, the Dumb Guy
- Codeforces Round #251(Div. 2) 439A. Devu, the Singer and Churu, the Joker 水题
- Codeforces Round #251 (Div. 2) 439C Devu and Partitioning of the Array(脑洞)
- Codeforces Round #251(Div. 2) 439C. Devu and Partitioning of the Array 构造
- Codeforces Round #251 (Div. 2) C Devu and Partitioning of the Array
- Codeforces Round #251 (Div. 2) D. Devu and his Brother
- Codeforces Round#251(Div 2)D Devu and his Brother
- Codeforces Round #251 (Div. 2) D Devu and his Brother
- 微博背后的那些算法
- 黑马程序员 IO流(二)
- VB6.0学习笔记 之 输入与输出(一)
- Java String.split()方法
- C#读取Excel2007的文件
- Codeforces Round #251 (Div. 2) 439B Devu, the Dumb Guy(贪心)
- 对象间的联动——观察者模式与Java事件处理(五)
- 程序员必须知道的10大基础实用算法及其讲解
- Pearson相关系数
- 循环-25. 求给定序列前N项和之三
- 并查集扩展之最小生成树Kruskal算法
- Objective-C id类型实现原理
- poj 3261
- Note on <Beginning Microsoft SQL Server 2012 Programming> - 05