CF439B.Devu, the Dumb Guy
普及-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Devu is a dumb guy, his learning curve is very slow. You are supposed to teach him n subjects, the i__th subject has c__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 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.
Devu 是个不太聪明的人,他的学习曲线非常缓慢。你需要教他 n 门课程,其中第 i 门课程包含 ci 章。
你在教学时,必须连续地讲授某门课程的所有章节(即不能中途切换到其他课程)。
假设他学习某一门课程时,每章的初始学习能力为 x 小时。换言之,他学习该课程中任意一章都需要 x 小时。
不过 Devu 并非完全愚笨——他也有优点:一旦你教完一门课程,那么他在学习下一门课程的任意一章时,所需时间将恰好比前一门课程每章所需时间减少 1 小时(参见样例以更清晰地理解)。注意:他每章所需的学习时间不能少于 1 小时。
你可以以任意顺序教授这 n 门课程。请找出 Devu 学完所有课程所需的最少总时间(单位:小时),这样你就能早日摆脱教学任务,去做些更有趣的事情了!
请注意:答案可能超出 32 位整数的数据范围。
输入格式
The first line will contain two space separated integers n, x (1 ≤ n, x ≤ 105). The next line will contain n space separated integers: _c_1, _c_2, ..., c__n (1 ≤ c__i ≤ 105).
第一行包含两个以空格分隔的整数 n、x(1 ≤ n, x ≤ 105)。
下一行包含 n 个以空格分隔的整数:c1, c2, ..., cn(1 ≤ ci ≤ 105)。
输出格式
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: 1, 2. When you teach Devu the first subject, it will take him 3 hours per chapter, so it will take 12 hours to teach first subject. After teaching first subject, his per chapter learning time will be 2 hours. Now teaching him second subject will take 2 × 1 = 2 hours. Hence you will need to spend 12 + 2 = 14 hours.
Consider the order of subjects: 2, 1. When you teach Devu the second subject, then it will take him 3 hours per chapter, so it will take 3 × 1 = 3 hours to teach the second subject. After teaching the second subject, his per chapter learning time will be 2 hours. Now teaching him the first subject will take 2 × 4 = 8 hours. Hence you will need to spend 11 hours.
So overall, minimum of both the cases is 11 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 3 hours per chapter. When you teach Devu the second subject, it will take him 2 hours per chapter. When you teach Devu the third subject, it will take him 1 hours per chapter. In total it takes 6 hours.
请看第一个例子。考虑科目的顺序:1、2。当你向Devu教授第一门科目时,他每章需要3小时,因此教授第一门科目总共需要 12 小时。教授完第一门科目后,他每章的学习时间将减少为 2 小时。此时教授第二门科目将耗时 2×1=2 小时。因此,你总共需要花费 12+2=14 小时。
再考虑科目的顺序:2、1。当你向Devu教授第二门科目时,他每章需要 3 小时,因此教授第二门科目总共需要 3×1=3 小时。教授完第二门科目后,他每章的学习时间将减少为 2 小时。此时教授第一门科目将耗时 2×4=8 小时。因此,你总共需要花费 11 小时。
综上,两种情况中的最小值为 11 小时。
请看第三个例子。本例中科目的讲授顺序无关紧要。当你向Devu教授第一门科目时,他每章需要 3 小时;教授第二门科目时,他每章需要 2 小时;教授第三门科目时,他每章需要 1 小时。总计耗时 6 小时。
输入解题思路,AI测评打分。不知道怎么写?