Codeforces Round #251 (Div. 2) 439B Devu, the Dumb Guy(贪心)

数据结构java课后习题答案 (1)以关键字序列(tim,kay,eva,roy,dot,jon,kim,ann,tom,jim,guy,amy)为例,手工执行以下排序算法 (按字典序比较关键字的大小),写出每一趟排序结束时的关键字状态: 1)直接插入排序; 2)冒泡排序; 3)直接选择排序; 4)快速排序; 5)归并排序; 6)基数排序。 立即下载

B. Devu, the Dumb Guy
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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

Sample test(s)
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 take3 × 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.




给出n个章节,每个章节需要的时间不同,每学一个章节,时间会减少1,但不会为0,问你最少时间是多少。


排序后加起来即可。


AC代码:


#include "iostream"
#include "cstdio"
#include "cstring"
#include "algorithm"
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 5;
int main(int argc, char const *argv[])
{
	int n;
	ll x;
	while(scanf("%d%lld", &n, &x) != EOF) {
		ll c[maxn];
		for(int i = 0; i < n; ++i)
			scanf("%lld", &c[i]);
		sort(c, c + n);
		ll ans = 0;
		for(int i = 0; i < n; ++i) {
			if(x == 1) ans += c[i];
			else {
				ans += (c[i] * x);
				x--;
			}
		}
		printf("%lld\n", ans);
	}
	return 0;
}


数据结构 练习题 答案 数据结构练习题答案 数据结构练习题答案 数据结构练习题答案 立即下载

相关推荐

java课后题答案(第一章)

java课后习题答案 希望可以对学习的人有所帮助

开发嵌套的标签

开发嵌套的标签:haveChildTag   实际工程中往往需要多个标签来配合完成一定的功能,嵌套的标签存在父子关系,其中,父为外层标签,子为内层标签。本实例将用两个简单的标签来演示,父标签则作出逻辑判断,如果isOutput属性为true,则输出实例108中的标签helloTag;如果为false,则不输出。   (1)第一步:开发标签实现类。   内层的标签helloTag在实例108中

求知 401

数据结构习题,以章节为单位,并附有答案

第一章绪论 一选择题 1. 算法的计算量的大小称为计算的( )。(B) A.效率 B. 复杂性 C. 现实性 D. 难度 2. 算法的时间复杂度取决于( )(C) A.问题的规模 B. 待处理数据的初态 C. A和B 3.计算机算法指的是(1),它必须具备(2) 这三个特性。(C B) (1) A.计算方法 B. 排序方法 C. 解决问题的步骤序列 D. 调度方法 (2) A.可执行性、可移植性、可扩充性 B. 可执行性、确定性、有穷性 C. 确定性、有穷性、稳定性 D. 易读性、稳定性、安全性 .... 第二章线性表 一 选择题 1.下述哪一条是顺序存储结构的优点?( )(A) A.存储密度大 B插入运算方便 C.删除运算方便 D可方便地用于各种逻辑结构的存储表示 2.下面关于线性表的叙述中,错误的是哪一个?( )(B) A.线性表采用顺序存储,必须占用一片连续的存储单元。 B.线性表采用顺序存储,便于进行插入和删除操作。 C.线性表采用链接存储,不必占用一片连续的存储单元。 D.线性表采用链接存储,便于插入和删除操作。 3.线性表是具有n个( )的有限序列(n>0)。(C) A.表元素 B.字符 C.数据元素 D.数据项 E.信息项 .... 第三章栈和队列 一 选择题 1.对于栈操作数据的原则是( )。(B) A. 先进先出 B. 后进先出 C. 后进后出 D. 不分顺序 2.在作进栈运算时,应先判别栈是否( ① ),在作退栈运算时应先判别栈是否( ② )。当栈中元素为n个,作进栈运算时发生上溢,则说明该栈的最大容量为( ③ )。(B A B) 为了增加内存空间的利用率和减少溢出的可能性,由两个栈共享一片连续的内存空间时,应将两栈的 ( ④)分别设在这片内存空间的两端,这样,当(⑤)时,才产生上溢。 (D C) ①, ②: A. 空 B. 满 C. 上溢 D. 下溢 ③: A. n-1 B. n C. n+1 D. n/2 ④: A. 长度 B. 深度 C. 栈顶 D. 栈底 ⑤: A. 两个栈的栈顶同时到达栈空间的中心点. B. 其中一个栈的栈顶到达栈空间的中心点. C. 两个栈的栈顶在栈空间的某一位置相遇. D. 两个栈均不空,且一个栈的栈顶到达另一个栈的栈底. ...

CodeForces 439B Devu, the Dumb Guy

Devu, the Dumb Guy Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Practice CodeForces 439B Description Devu is a dumb guy, his learning c

一只叫做Unix的猫 1048

数据结构各章习题与答案

数据结构各章习题与答案,对复习蛮有帮助的,可以看下

算法数据结构及课后习题答案

算法数据结构及课后习题答案,非常全面,都是本人上课收集老师的

B. Devu, the Dumb Guy

解题说明:此题就从小到大排序,这样就能保证最少时间,但是要注意y

无知的我 1448

Java数据结构和算法(第二版)带目录和习题答案

Java数据结构和算法(第二版)带目录和习题答案!

Codeforces Round #251(Div. 2) 439B. Devu, the Dumb Guy 贪心

B. Devu, the Dumb Guy time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Devu is a dumb guy, his learning curve

Jonariguez 吾本优秀 711

java个中算法习题,答案

java程序的各种知名算法,数字排列程序有错,如若找这种的请勿下载 浪费积分

数据结构 第一章习题及答案

数据结构 第一章习题及答案,学习数据结构的童鞋可以下载下来看看

【索引】Codeforces Round #251 (Div. 2)

Problem A: Devu, the Singer and Churu, the Joker(439A)

不慌不忙、不急不躁 849

数据结构:java语言 第一章

第一章课件,英语原版,希望大家喜欢,会继续传以下的章节

指针习题6(答案版)

题目及楼主的方法 答案的代码 #include&lt;stdio.h&gt; int main() {int length(char *p); int len; char str[20]; printf("input string: "); scanf("%s",str); len=length(str); printf("The length of string is %d.\n"...

成长之路 530

ICT模拟零件测试方法--电容测试

通常,小到 100 pF 的电容需要补偿,因为夹具和系统的电容(20 到 50 pF)相对于被测设备的值是显著的。软件在需要补偿的电容测试中加入 comp 选项,而在不需要补偿的电容测试中加入 nocomp 选项。在调试期间,通过向电容语句添加 pc 选项验证您的电容测试。在测试单独的电容时,从测量结果中减去学到的值,然后与测试限制进行比较以决定通过或失败。请注意,如果用于需要补偿的电容测试上的感应总线使用了单独的探针,测量将无效。在测试电容时,应注意两个方面:电容的电阻元件,以及夹具和系统本身的电容。

可可南木的博客 1234

Vivado2022.2下载安装

链接:https://pan.baidu.com/s/1lyfE2d-VmaWC-_aR8ratCQ提取码:mt09。

weixin_61081689的博客 2万+

Devu, the Dumb Guy

Description Devu is a dumb guy, his learning curve is very slow. You are supposed to teach him n subjects, the ith subject has ci chapters. When you teach him, you are supposed to teach all the c

打得一手好铁 551

宇树智能人形机器人模块化腿部动力系统技术拆解

o电机防摔防护板(3.1.5.1)→端盖总成(3.1.5.2)→电机外壳(3.1.5.4)的冲击力传递路径;o散热风扇(3.1.3.1)推动冷风→大腿基座腔体→散热片组(3.1.5.7)→中空大腿杆排出;o防御专利:覆盖“关节热管理风道接口标准”、“抗冲击结构身份编码”;o大腿杆腔体(3.1.3.4)内置反平行四边形机构,避免连杆外露。:力传感器(3.1.8.4.2)仅部署于足端,缺失关节力矩反馈。:更换行星减速器(3.1.5.5)需拆解整个电机模块;o热量传导路径:电机定子→外壳→散热片组。

weixin_50955533的博客 1245

EVA 新剧场版 序

终于明白为什么我很难买到动感新势力了,因为它每次都是月中的时候出下个月的,而我是半个月后才去看有没有新的! 不过 6 月份的我倒是没错过。5 月份上面就有预告说下期附赠 EVA 新剧场版。所以买回来第一件事是看剧场版,而不是跟以前样的先听 CD。 画面上看总的来说还是主流水平,情节跟以前基本是一样的,但是叙事方式有所变化。因为几乎所有观众都了解背景故事,所以没有花什么篇幅讲解死海文书和...

remember1989的专栏 730

CREO5.0二次开发+VS2019配置详解

CREO5.0+VS2019配置更新 一、CREO5.0 配置 二、Visual Studio 2019配置 新建MFC DLL项目 文件>新建>项目,选择MFC DLL,如下图所示 项目名称CREO1 2、配置设置 打开项目属性: 配置资源管理器设置: 设置包含目录、库目录(根据自己CREO的安装位置来设置): 包含目录: 库目录: 预处理器设置: 把下面文字复...

liuyi2517的博客 1万+

使用Matlab进行IEEE 33节点潮流计算的NR法实现详解及应用实例

IEEE 33节点系统是一个标准的配电系统模型,广泛用于学术研究和工程应用。该系统由33个节点和37条线路组成,结构复杂,具有代表性。其潮流计算结果可用于验证各种潮流计算方法的准确性和效率。NR法是一种基于迭代求解的潮流计算方法,通过不断迭代求解非线性方程组,直到达到预定的收敛条件。NR法具有收敛速度快、计算精度高的优点,适用于大规模复杂电力系统的潮流计算。

m0_57781768的博客 2075

内部排序-第10章-《数据结构题集》习题解析-严蔚敏吴伟民版

习题集解析部分 第10章 内部排序 ——《数据结构题集》-严蔚敏.吴伟民版        源码使用说明  链接☛☛☛ 《数据结构-C语言版》(严蔚敏,吴伟民版)课本源码+习题集解析使用说明        课本源码合辑  链接☛☛☛ 《数据结构》课本源码合辑        习题集全解析  链接☛☛☛ 《数据结构题集》习题解析合辑         相关测试数据下载  链接☛ 数据包  ...

weixin_33713503的博客 1万+

ISP-全局色调映射(GTM)算法简单实现

色调映射算法,色彩空间转换LAB

notgoodenouf的博客 2248
上一篇: Codeforces Round #201 (Div. 2) 347C Alice and Bob(脑洞)
下一篇: Codeforces Round #251 (Div. 2) 439C Devu and Partitioning of the Array(脑洞)
GKHack
博客等级 码龄12年 48粉丝 291原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值