StarCraft

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/HYNU_zhizuzhe/article/details/50849297

Problem Description

ZB loves playing StarCraft and he likes Zerg most!

One day, when ZB was playing SC2, he came up with an idea:

He wants to change the queen's ability, the queen's new ability is to choose a worker at any time, and turn it into an egg, after K units of time, two workers will born from that egg. The ability is not consumed, which means you can use it any time without cooling down.

Now ZB wants to build N buildings, he has M workers initially, the i-th building costs t[i] units of time, and a worker will die after he builds a building. Now ZB wants to know the minimum time to build all N buildings.

Input

The first line contains an integer T, meaning the number of the cases. 1 <= T <= 50.

For each test case, the first line consists of three integers N, M and K. (1 <= N, M <= 100000, 1 <= K <= 100000).

The second line contains N integers t[1] ... t[N](1 <= t[i] <= 100000).

Output

For each test case, output the answer of the question.

Sample Input

2
3 1 1
1 3 5
5 2 2
1 1 1 1 10

Sample Output

6
10

Hint

For the first example, turn the first worker into an egg at time 0, at time 1 there’s two worker. And use one of them to build the third building, turn the other one into an egg, at time 2, you have 2 workers and a worker building the third building. Use two workers build the first and the second building, they are built at time 3, 5, 6 respectively. 

题意:已知n件工作,m个工人,一个工人完成一件事所需时间t,并且工作完后那个工人不在工作,领导者可以使未工作的工人在k秒后变成两人,求完成所有工作所需最少时间

#include<iostream>
#include<cstdio>
#include<queue>
using namespace std;

#define max(a,b) (a>b ? a:b)

int main()
{
	int T_T;
	scanf("%d",&T_T);
	while(T_T--)
	{
		int n,m,k,q,i;
		priority_queue<int,vector<int>,greater<int> > que;
		scanf("%d%d%d",&n,&m,&k);
		for(i=0;i<n;i++)
		{
			scanf("%d",&q);
			que.push(q);
		}
		while(n>m)
		{
			que.top(); que.pop();
			q=que.top(); que.pop();
			que.push(q+k);
			n--;
		}
		int ans=0;
		while(!que.empty())
		{
			ans=max(ans,que.top());
			que.pop();
		}
		printf("%d\n",ans);
	}
	return 0;
}

方法:Huffman


猜你喜欢

转载自blog.csdn.net/HYNU_zhizuzhe/article/details/50849297