A9527 | Devu, the Dumb Guy
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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.
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<=10^{5}$ ). The next line will contain $n$ space separated integers: $c_{1},c_{2},...,c_{n}$ ( $1<=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: $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.
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.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted