GTY's birthday gift
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1080 Accepted Submission(s): 413
Problem Description
FFZ's birthday is coming. GTY wants to give a gift to ZZF. He asked his gay friends what he should give to ZZF. One of them said, 'Nothing is more interesting than a number multiset.' So GTY decided to make a multiset for ZZF. Multiset can contain elements with same values. Because GTY wants to finish the gift as soon as possible, he will use JURUO magic. It allows him to choose two numbers a and b(
a,b∈S), and add
a+b to the multiset. GTY can use the magic for k times, and he wants the sum of the multiset is maximum, because the larger the sum is, the happier FFZ will be. You need to help him calculate the maximum sum of the multiset.
Input
Multi test cases (about 3) . The first line contains two integers n and k (
2≤n≤100000,1≤k≤1000000000). The second line contains n elements
ai (
1≤ai≤100000)separated by spaces , indicating the multiset S .
Output
For each case , print the maximum sum of the multiset (
mod 10000007).
Sample Input
Sample Output
Source
BestCoder Round #29
问题描述
GTY的朋友ZZF的生日要来了,GTY问他的基友送什么礼物比较好,他的一个基友说送一个可重集吧!于是GTY找到了一个可重集S,GTY能使用神犇魔法k次,每次可以向可重集中加入一个数 a+b (a,b\in S)a+b(a,b∈S),现在GTY想最大化可重集的和,这个工作就交给你了。
注:可重集是指可以包含多个相同元素的集合
输入描述
多组数据(约3组),每组数据的第一行有两个数n,k(2 \leq n \leq 100000,1 \leq k \leq 1000000000)n,k(2≤n≤100000,1≤k≤1000000000) 表示初始元素数量和可使用的魔法数,第二行包含n个数a(1 \leq a_i \leq 100000)a(1≤ai≤100000)表示初始时可重集的元素
输出描述
对于每组数据,模10000007输出可重集可能的最大和。
输入样例
3 2
3 6 2
输出样例
35
解题思路:对于每次使用魔法,只需要选取当前序列a[]中最大的两个数a和b,加和放入序列a[]组成新序列a[]。
对于开始的序列a[],选取最大的两个数a和b(假设a>b),那么第一次使用魔法后新序列的最大的两个数为(a+b)和a。
代码如下:
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include