CF439B.Devu, the Dumb Guy

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Devu is a dumb guy, his learning curve is very slow. You are supposed to teach him nn subjects, the ithi^{th} subject has cic_{i} 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 xx hours. In other words he can learn a chapter of a particular subject in xx 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 nn 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 nn , xx ( 1<=n,x<=1051<=n,x<=10^{5} ). The next line will contain nn space separated integers: c1,c2,...,cnc_{1},c_{2},...,c_{n} ( 1<=ci<=1051<=c_{i}<=10^{5} ).

输出格式

Output a single integer representing the answer to the problem.

输入输出样例

  • 输入#1

    2 3
    4 1
    

    输出#1

    11
    
  • 输入#2

    4 2
    5 1 2 1
    

    输出#2

    10
    
  • 输入#3

    3 3
    1 1 1
    

    输出#3

    6
    

说明/提示

Look at the first example. Consider the order of subjects: 11 , 22 . When you teach Devu the first subject, it will take him 33 hours per chapter, so it will take 1212 hours to teach first subject. After teaching first subject, his per chapter learning time will be 22 hours. Now teaching him second subject will take 2×1=22×1=2 hours. Hence you will need to spend 12+2=1412+2=14 hours.

Consider the order of subjects: 22 , 11 . When you teach Devu the second subject, then it will take him 33 hours per chapter, so it will take 3×1=33×1=3 hours to teach the second subject. After teaching the second subject, his per chapter learning time will be 22 hours. Now teaching him the first subject will take 2×4=82×4=8 hours. Hence you will need to spend 1111 hours.

So overall, minimum of both the cases is 1111 hours.

Look at the third example. The order in this example doesn't matter. When you teach Devu the first subject, it will take him 33 hours per chapter. When you teach Devu the second subject, it will take him 22 hours per chapter. When you teach Devu the third subject, it will take him 11 hours per chapter. In total it takes 66 hours.

首页