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
3 2 3 6 2
Sample Output
35
Source
BestCoder Round #29
Recommend
hujie | We have carefully selected several similar problems for you: 5173 5172 5169 5168 5165
設現在拿出的數為a和b,且a >= b,則下一次拿出的數為 a + b, a
存在遞推關系,得到遞推矩陣後,快速冪求解即可,復雜度O(logn)
/*************************************************************************
> File Name: hdu5171.cpp
> Author: ALex
> Mail: [email protected]
> Created Time: 2015年02月14日 星期六 10時48分07秒
************************************************************************/
#include