B. Devu, the Dumb Guy

17 篇文章 0 订阅
B. Devu, the Dumb Guy
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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.

Input

The first line will contain two space separated integers nx (1 ≤ n, x ≤ 105). The next line will contain n space separated integers:c1, c2, ..., cn (1 ≤ ci ≤ 105).

Output

Output a single integer representing the answer to the problem.

Sample test(s)
input
2 3
4 1
output
11
input
4 2
5 1 2 1
output
10
input
3 3
1 1 1
output
6
Note
#include <iostream>
#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;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值