CF226B.Naughty Stone Piles

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

There are nn piles of stones of sizes a1,a2,...,ana_{1},a_{2},...,a_{n} lying on the table in front of you.

During one move you can take one pile and add it to the other. As you add pile ii to pile jj , the size of pile jj increases by the current size of pile ii , and pile ii stops existing. The cost of the adding operation equals the size of the added pile.

Your task is to determine the minimum cost at which you can gather all stones in one pile.

To add some challenge, the stone piles built up conspiracy and decided that each pile will let you add to it not more than kk times (after that it can only be added to another pile).

Moreover, the piles decided to puzzle you completely and told you qq variants (not necessarily distinct) of what kk might equal.

Your task is to find the minimum cost for each of qq variants.

输入格式

The first line contains integer nn (1<=n<=105)(1<=n<=10^{5}) — the number of stone piles. The second line contains nn space-separated integers: a1,a2,...,ana_{1},a_{2},...,a_{n} (1<=ai<=109)(1<=a_{i}<=10^{9}) — the initial sizes of the stone piles.

The third line contains integer qq (1<=q<=105)(1<=q<=10^{5}) — the number of queries. The last line contains qq space-separated integers k1,k2,...,kqk_{1},k_{2},...,k_{q} (1<=ki<=105)(1<=k_{i}<=10^{5}) — the values of number kk for distinct queries. Note that numbers kik_{i} can repeat.

输出格式

Print qq whitespace-separated integers — the answers to the queries in the order, in which the queries are given in the input.

Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.

输入输出样例

  • 输入#1

    5
    2 3 4 1 1
    2
    2 3
    

    输出#1

    9 8 

说明/提示

In the first sample one way to get the optimal answer goes like this: we add in turns the 44 -th and the 55 -th piles to the 22 -nd one; then we add the 11 -st pile to the 33 -rd one; we add the 22 -nd pile to the 33 -rd one. The first two operations cost 11 each; the third one costs 22 , the fourth one costs 55 (the size of the 22 -nd pile after the first two operations is not 33 , it already is 55 ).

In the second sample you can add the 22 -nd pile to the 33 -rd one (the operations costs 33 ); then the 11 -st one to the 33 -th one (the cost is 22 ); then the 55 -th one to the 44 -th one (the costs is 11 ); and at last, the 44 -th one to the 33 -rd one (the cost is 22 ).

首页