B. Devu, the Dumb Guy
来源:互联网 发布:淘宝送优酷会员怎么用 编辑:程序博客网 时间:2024/04/29 18:51
Devu is a dumb guy, his learning curve is very slow. You are supposed to teach him n subjects, the ith subject has ci chapters. When you teach him, you are supposed to teach all the chapters of a subject continuously.
Let us say that his initial per chapter learning power of a subject is x hours. In other words he can learn a chapter of a particular subject in x hours.
Well Devu is not complete dumb, there is a good thing about him too. If you teach him a subject, then time required to teach any chapter of the next subject will require exactly 1 hour less than previously required (see the examples to understand it more clearly). Note that his per chapter learning power can not be less than 1 hour.
You can teach him the n subjects in any possible order. Find out minimum amount of time (in hours) Devu will take to understand all the subjects and you will be free to do some enjoying task rather than teaching a dumb guy.
Please be careful that answer might not fit in 32 bit data type.
The first line will contain two space separated integers n, x (1 ≤ n, x ≤ 105). The next line will contain n space separated integers:c1, c2, ..., cn (1 ≤ ci ≤ 105).
Output a single integer representing the answer to the problem.
2 34 1
11
4 25 1 2 1
10
3 31 1 1
6
#include <stdio.h>
#include <algorithm>
using namespace std;
#define maxn 100005
int main()
{
long long int num[maxn] = {0};
long long sum = 0;
long long n,x;
scanf("%lld %lld",&n, &x);
for( int i = 0; i<n; i++)
{
scanf("%lld",&num[i]);
}
sort(num,num+n);
for(int i = 0; i<n; i++)
{
sum += num[i]*x;
if(x!= 1)
x--;
}
printf("%lld\n",sum);
return 0;
}
- B. Devu, the Dumb Guy
- B. 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
- Devu, the Dumb Guy
- Codeforces 439B Devu, the Dumb Guy(贪心)
- Codeforces Round #251 (Div. 2) 439B Devu, the Dumb Guy(贪心)
- Codeforces Round #251(Div. 2) 439B. Devu, the Dumb Guy 贪心
- The first guy
- I'm the new guy here
- A. I Wanna Be the Guy
- 469A - I Wanna Be the Guy
- 【CodeForces】A. I Wanna Be the Guy
- Make Anonymous be the lucky guy
- Codeforces I Wanna Be the Guy
- 关于++和--运算符的理解
- Swift的?语法在函数参数的使用
- windows xp添加开机自启动脚本
- spring aop expression支持多个表达式配置
- UI程序启动之application
- B. Devu, the Dumb Guy
- 缩略图片
- oracle格式化输出
- mysql 主从复制
- 学习总结之 时间数字格式化
- zend studio for eclipse 设置及 debug 页面跳转调试
- java向上转型
- 接水问题
- 关于java的接口回调和向上转型的理解