CF BUDDY
← Problems·

1951C · Ticket Hoarding

1400 · greedy, math, sortings

Problem: As the CEO of a startup company, you want to reward each of your kk employees with a ticket to the upcoming concert. The tickets will be on sale for nn days, and by some time travelling, you have predicted that the price per ticket at day ii will be aia_i. However, to prevent ticket hoarding, the concert organizers have implemented the following measures:

  • A person may purchase no more than mm tickets per day.
  • If a person purchases xx tickets on day ii, all subsequent days (i.e. from day i+1i+1 onwards) will have their prices per ticket increased by xx.

For example, if a=[1,3,8,4,5]a = [1, 3, 8, 4, 5] and you purchase 22 tickets on day 11, they will cost 22 in total, and the prices from day 22 onwards will become [5,10,6,7][5, 10, 6, 7]. If you then purchase 33 more tickets on day 22, they will cost in total an additional 1515, and the prices from day 33 onwards will become [13,9,10][13, 9, 10].

Find the minimum spending to purchase kk tickets.

Input Format: Each test contains multiple test cases. The first line contains an integer tt (1t1041 \le t \le 10^4) — the number of test cases. The description of the test cases follows.

The first line of each test case contains three integers nn, mm, and kk (1n3105,1m109,1kmin(nm,109)1 \le n \le 3 \cdot 10^5, 1 \le m \le 10^9, 1 \le k \le \min(nm, 10^9)) — the number of sale days, the maximum amount of ticket purchasable each day, and the number of tickets to be bought at the end.

The second line of each test case contains nn integers a1,a2,,ana_1, a_2, \ldots, a_n (1ai1091 \le a_i \le 10^9) — the price per ticket for each of the upcoming nn days.

It is guaranteed that the sum of nn over all test cases does not exceed 31053 \cdot 10^5.

Output Format: For each test case, print one integer: the minimum amount of money needed to purchase exactly kk tickets.

Note: In the first test case, one optimal way to buy 33 tickets is as follows:

  • Buy 00 tickets on the first day. The prices per ticket for the remaining days are [6,4,2][6, 4, 2].
  • Buy 00 tickets on the second day. The prices per ticket for the remaining days are [4,2][4, 2].
  • Buy 11 ticket on the third day with cost 44. The price per ticket for the remaining day is [3][3].
  • Buy 22 tickets on the fourth day with cost 66.

In the second test case, there is only one way to buy 88 tickets:

  • Buy 22 tickets on the first day with cost 1616. The prices per ticket for the remaining days are [8,6,4][8, 6, 4].
  • Buy 22 tickets on the second day with cost 1616. The prices per ticket for the remaining days are [8,6][8, 6].
  • Buy 22 tickets on the third day with cost 1616. The price per ticket for the remaining day is [8][8].
  • Buy 22 tickets on the fourth day with cost 1616.

Sample Cases

Case 1

Input

4
4 2 3
8 6 4 2
4 2 8
8 6 4 2
5 100 1
10000 1 100 10 1000
6 3 9
5 5 5 5 5 5

Output

10
64
1
72

Similar problems

00:00:00
Loading editor…
Welcome! I'm your coding tutor for this problem. Use the chips below to reveal stored hints or get AI feedback on your code. I'll guide you step by step — never giving away the solution.

Sign in to unlock AI tutor feedback