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. Linux x64 -- 内核程序(驱动程序)读取任意进程数据实现

    四级页表结构 现在的64位Linux系统中,并没有使用全部的64位地址空间,而是使用其低48位,高16位并没有使用. 其中 39至47这9位用于索引PGD(page global directory) ...

  2. USB to UART

    USB to UART: 芯片选用CH340: 电源部分连接两个电容分别是0.1微法和10微法: 晶振连接12MHz; D+ D-  连接单片机的D+ D-

  3. <转>jmeter(十七)目录结构

    之前了解过jmeter的目录结构,但只知道一些常用的配置文件,看到一篇介绍的比较详细的博客,就转载过来,当然,其实是自己懒得再去搜集更多资料慢慢看了,时间不够用... 原文链接:http://www. ...

  4. 《Google软件测试之道》测试开发工程师

    拖延了将近半年的草稿,断断续续的写完了.之前草草翻看完这本书,关注点主要在TE上,而关于SET的部分则只是浏览,最近后知后觉,又翻出了这本书,重新看了一遍,又有新收获. 就说说Google的SET是如 ...

  5. fastcgi_next_upstream error timeout invalid_header http_500 http_503(转)

    location / proxy_pass http://nodelist; fastcgi_next_upstream error timeout invalid_header http_500 h ...

  6. grep配置颜色显示

    查日志时候必须要用的命令,为了在终端方便显示查看,可以加颜色和高亮等设置. 自己习惯用的: GREP_COLOR='a;b'  a=4表示下划线,b=41表示红色背景高亮 在~/.bashrc文件中加 ...

  7. SQLServer 窗口函数(转载)

    一.窗口函数的作用 窗口函数是对一组值进行操作,不需要使用GROUP BY 子句对数据进行分组,还能够在同一行中同时返回基础行的列和聚合列.窗口函数,基础列和聚合列的查询都非常简单. 二.语法格式 窗 ...

  8. LiveCharts文档-3开始-5序列Series

    原文:LiveCharts文档-3开始-5序列Series LiveCharts文档-3开始-5序列Series Strokes和Fills 笔触和填充 所有的Series都有笔触和填充属来处理颜色, ...

  9. VMware Ubuntu蓝屏问题解决

    解决方法: 问题分析启动 Ubuntu 可以进入登录界面,说明系统是可以运行起来的.没有发生大块的核心数据损坏,linux 系统一般都可以修复,一定要淡定.于是开始放狗(google)搜索.“VMwa ...

  10. Docker容器学习梳理 - Volume数据卷使用

    之前部署了Docker容器学习梳理--基础环境安装,接下来看看Docker Volume的使用. Docker volume使用 Docker中的数据可以存储在类似于虚拟机磁盘的介质中,在Docker ...