codeforces439B
Devu, the Dumb Guy
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 n, x (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
2 3
4 1
11
4 2
5 1 2 1
10
3 3
1 1 1
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的更多相关文章
随机推荐
- Luogu4131 WC2005 友好的生物 状压DP
传送门 首先$C_i$是没有意义的,因为可以直接让$d_i \times= C_i$,答案也是一样的 所以我们现在考虑求$(\sum_{i=1}^{K-1} |d_{p,i}-d_{q,i}|) - ...
- Git .gitignore文件的使用
本文转载自 http://blog.csdn.net/xmyzlz/article/details/8592302 在git中如果想忽略掉某个文件,不让这个文件提交到版本库中,可以使用修改 .giti ...
- SpringMVC之单/多文件上传
1.准备jar包(图标所指必备包,其他按情况导入) 2.项目结构 3.SingleController.java(控制器代码单文件和多文件) package com.wt.uplaod; import ...
- NOIP2018题解
Preface 联赛结束后趁着自己还没有一下子把题目忘光,所以趁机改一下题目. 没有和游记一起写主要是怕篇幅太长不美观. 因此这里我们直接讲题目,关于NOIP2018的一些心得和有趣的事详见:NOIP ...
- socket、tcp、udp、http 的认识及区别
一.先来一个讲TCP.UDP和HTTP关系的 1.TCP/IP是个协议组,可分为三个层次:网络层.传输层和应用层. 在网络层有IP协议.ICMP协议.ARP协议.RARP协议和BOOTP协议. 在传输 ...
- Roslyn入门(一)-C#语法分析
演示环境 Visual Studio 2017 .NET Compiler Platform SDK 简介 今天,Visual Basic和C#编译器是黑盒子:输入文本然后输出字节,编译管道的中间阶段 ...
- 如何手动写一个Python脚本自动爬取Bilibili小视频
如何手动写一个Python脚本自动爬取Bilibili小视频 国庆结束之余,某个不务正业的码农不好好干活,在B站瞎逛着,毕竟国庆嘛,还让不让人休息了诶-- 我身边的很多小伙伴们在朋友圈里面晒着出去游玩 ...
- 重建索引解决mssql表查询超时的问题
表已有数据,150万+,执行一个group by 的查询出现超时,一个一个条件减少尝试,前几个where条件不超时,而在加上最后一个条件时就超时了. 分析表的索引建立情况:DBCC showconti ...
- vs2017+opencv4.0.1安装配置详解(win10)
一.说明 笔者之前已经安装过了vs2017,对应的opencv是3.4.0版本的.但现在想体验下opencv4的改变之处,所以下载了最新的opencv4.0.1. vs2017的安装请自行搜索安装,本 ...
- 对于windows 10使用感受
windows 10是美国微软公司研发的新一代跨平台及设备应用的操作系统.在2015年7月29日12点起,windows 10推送全面开始,windows 7.windows 8 用户可以升级到win ...