Devu, the Dumb Guy

CodeForces - 439B

Devu is a dumb guy, his learning curve is very slow. You are supposed to teach him nsubjects, 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.

Examples

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

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.

sol:较显然的贪心,从小到大排序后先学小的再学大的

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
inline ll read()
{
ll s=;
bool f=;
char ch=' ';
while(!isdigit(ch))
{
f|=(ch=='-'); ch=getchar();
}
while(isdigit(ch))
{
s=(s<<)+(s<<)+(ch^); ch=getchar();
}
return (f)?(-s):(s);
}
#define R(x) x=read()
inline void write(ll x)
{
if(x<)
{
putchar('-'); x=-x;
}
if(x<)
{
putchar(x+''); return;
}
write(x/);
putchar((x%)+'');
return;
}
#define W(x) write(x),putchar(' ')
#define Wl(x) write(x),putchar('\n')
const int N=;
int n;
long long X,A[N];
int main()
{
int i;
ll ans=;
R(n); R(X);
for(i=;i<=n;i++) R(A[i]);
sort(A+,A+n+);
for(i=;i<=n;i++)
{
ans+=1ll*X*A[i];
if(X>) X--;
}
Wl(ans);
return ;
}
/*
input
2 3
4 1
output
11 input
4 2
5 1 2 1
output
10 input
3 3
1 1 1
output
6
*/

codeforces439B的更多相关文章

随机推荐

  1. Skyline从5.1升级版本到6.5的常见接口变化问题

    1.原来Route对象升级成Presentation对象后,激活方法的变化: 原来5.1版本示例代码: function flyto(thisa) { var thisid = thisa.id; v ...

  2. UVA11255 Necklace Burnside、组合

    VJ传送门 因为有每种颜色个数的限制,所以不能使用Polya 考虑退一步,使用Burnside引理求解 回忆一下Burnside引理,它需要求的是置换群中每一个置换的不动点个数,也就是施加一次置换之后 ...

  3. python 3.5下安装pycrypto

    pip install --use-wheel --no-index --find-links=https://github.com/sfbahr/PyCrypto-Wheels/raw/master ...

  4. RabbmitMQ-Publish/Subscribe

    之前的学习中,我们了解的工作队列实现的是:一个消息只发送到一个消费者. 现在我们来学习一下新模式:发布/订阅模式 之前我们在原理中介绍了exchange,但好像并没有使用.而是直接往队列里发消息和取消 ...

  5. 马加爵遗书 VS 药家鑫遗书

          前言:今天是贰零壹柒年最后一个工作日,亦是2017年12月29日,因为明天就放元旦假了,公司同事比往常相对轻松些.中午吃完午饭,在办公室大家有说有笑,有人说姓马的人都挺牛X啊,比如:马云, ...

  6. 基于uFUN开发板的心率计(二)动态阈值算法获取心率值

    前言 上一篇文章:基于uFUN开发板的心率计(一)DMA方式获取传感器数据,介绍了如何获取PulseSensor心率传感器的电压值,并对硬件电路进行了计算分析.心率计,重要的是要获取到心率值,本篇文章 ...

  7. Websocket(一)——原理及基本属性和方法

    初次接触 WebSocket 的人,都会问同样的问题:我们已经有了 HTTP 协议,为什么还需要另一个协议?它能带来什么好处? 答案很简单,因为 HTTP 协议有一个缺陷:通信只能由客户端发起. 举例 ...

  8. hdu 1263 水果 结构的排序+sort自定义排序

    水果 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submissi ...

  9. [2017BUAA软工]第零次博客作业

    第一部分:结缘计算机 1. 你为什么选择计算机专业?你认为你的条件如何?和这些博主比呢?(必答) 当年高考前在专业这件事上纠结了好久,因为我对于大学各个专业具体学什么都不甚了解,于是就迟迟没有明确的目 ...

  10. Ubuntu 服务器指南

    https://help.ubuntu.com/lts/serverguide/   Jabber Instant Messaging Server https://help.ubuntu.com/l ...