Gym - 102219K :Help The Support Lady(贪心)

Nina是一名软件公司的IT支持人员,面对多个客户请求,她必须在2倍的预估时间内响应,以确保客户满意。本文介绍了一个算法,帮助Nina通过合理安排工作顺序,最大化满足客户需求的数量。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

http://codeforces.com/gym/102219/problem/K

Nina works as an IT support in a software company and always busy. The biggest issue she is facing is that sometimes she misses some deadlines. In their team the time needed to finish each customer request is estimated based on experience, 1≤x≤105. The moment a request is submitted, she has double of the estimated time to respond to the request, 2x. Meaning if the request A was submitted at 12pm and takes 2 hours to finish, she can wait 2 hours and then work on it for 2 hours and still finish the job on time, by 4

pm and the customer would be satisfied.

Sometimes there is not enough capacity and she has to pick up a lot of requests, and it is expected to miss some deadlines. But she needs your help, to see if arrange correctly what are the maximum requests she can finish before their deadlines.

Let's assume that she has the list of the requests and their deadline immediately as she starts working every day and she doesn't take any break until she is done with all of them.

Input

The first line contains integer m(1≤m≤20). Number of cases.The second line contains integer n(1≤n≤105). Number of the requests.The last line contains nintegers ti (1≤ti≤109), separated by spaces. Estimated time each request should be responded so the customer would be happy.

Output

Print the case number and a single number - the maximum number of satisfied customer for each case.

Example

Input

1
5
15 2 1 5 3

Output

Case #1: 4

Note

If she responds to the request with this order 1, 2, 3, 5, 15, the only customer with the request that requires 5 hours wouldn't be happy.

 

题意分析:

Nina每天工作的时候有n个待完成的工作,每个工作需要x时间来完成,可以在2x之前提交,求最多可以成功提交的工作有多少个。

解题思路:

首先要从时间短的开始做,因为先做时间长的在做短的,短的就有可能超时,所以先按时间排序,

如果一项工作完成之后超过了提交时间,那么这项工作从一开始就不用做,可以结束时间去做其他工作,

所以贪心策略是先判断做这项工作能否在2x之前提交,如果可以,做这项工作,否则,跳过这项工作。

#include <stdio.h>
#include <algorithm>
#define N 100020
using namespace std;
long long  a[N];
int main()
{
	int T, t=0, n;
	scanf("%d", &T);
	while(T--)
	{
		scanf("%d", &n);
		for(int i=0; i<n; i++)
			scanf("%lld", &a[i]);
		sort(a, a+n);
		long long sum=0;
		int ans=0;
		for(int i=0; i<n; i++)
		{
			if(sum<=a[i])
			{
				sum+=a[i];
				ans++;
			}
		}
		printf("Case #%d: %d\n", ++t, ans);
	}
	return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

张宜强

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值