每日一题 第八十一期 Codeforces Global Round 25

C. Ticket Hoarding

time limit per test: 2 seconds

memory limit per test: 256 megabytes

input: standard input

output: standard output

Maître Gims - Est-ce que tu m’aimes ?

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

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

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

Find the minimum spending to purchase k k k tickets.

Input

Each test contains multiple test cases. The first line contains an integer t t t ( 1 ≤ t ≤ 1 0 4 1 \le t \le 10^4 1t104) — the number of test cases. The description of the test cases follows.

The first line of each test case contains three integers n n n, m m m, and k k k ( 1 ≤ n ≤ 3 ⋅ 1 0 5 , 1 ≤ m ≤ 1 0 9 , 1 ≤ k ≤ min ⁡ ( n m , 1 0 9 ) 1 \le n \le 3 \cdot 10^5, 1 \le m \le 10^9, 1 \le k \le \min(nm, 10^9) 1n3105,1m109,1kmin(nm,109)) — 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 n n n integers a 1 , a 2 , … , a n a_1, a_2, \ldots, a_n a1,a2,,an ( 1 ≤ a i ≤ 1 0 9 1 \le a_i \le 10^9 1ai109) — the price per ticket for each of the upcoming n n n days.

It is guaranteed that the sum of n n n over all test cases does not exceed 3 ⋅ 1 0 5 3 \cdot 10^5 3105.

Output

For each test case, print one integer: the minimum amount of money needed to purchase exactly k k k tickets.
Example
inputCopy
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
outputCopy
10
64
1
72

AC代码:

#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<queue>
#include<string>
#include<bitset>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<numeric>
#include<iomanip>
#define endl '\n'
using namespace std;

typedef long long ll;
typedef pair<int, int>PII;
const int N=3e5+10;
const int MOD=1e9 + 7;
const int INF=0X3F3F3F3F;
const int dx[]={-1,1,0,0,-1,-1,+1,+1};
const int dy[]={0,0,-1,1,-1,+1,-1,+1};
const int M = 1e6 + 10;

int t;
ll n, m, k;
ll a[N];

int main()
{
	cin >> t;
	while(t --){
		cin >> n >> m >> k;
		for(int i = 1; i <= n; i ++)
		{
			cin >> a[i];
		}
		ll sum = 0, res = 0;
		sort(a + 1, a + 1 + n);
		for(int i = 1; i <= n; i ++)
		{
			if(k >= m)
			{
				sum += m * a[i];
				res += m;
				a[i + 1] += res;
				k -= m;
			}
			else {
				sum += k * a[i];
				break;
			}
		}
		cout << sum << endl;
	}
	
	return 0;
}
  • 23
    点赞
  • 28
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值