BNU Rugby Football

#include <stdio.h>
#include <stdlib.h>
#define ll long long
ll v[10050];
int cmp(const void *a,const void *b)
{
	return *(ll *)b - *(ll *)a;	
}
int main()
{
	ll T,n,time,L,i,total;
	double ans;
	scanf("%lld",&T);
	while(T--)
	{
		scanf("%lld%lld%lld",&n,&time,&L);
		total = L;
		for(i=1;i<=n;i++){
			scanf("%lld",&v[i]);	
			total -= v[i]*time;
		}
		if(total > 0)
		{
			printf("-1\n");
			continue;	
		}
		qsort(&v[1],n,sizeof(v[1]),cmp);
		ll sum=0;
		for(i=1;i<=n;i++)
		{
			if(sum + v[i]*time >= L)
			{
				L -= sum;
				ans = time * (i-1) * 1.0;	
				break;
			}	
			sum += v[i]*time;
		}
		ans += L*1.0/v[i];
		printf("%.2lf\n",ans);
	}	
}
做道水题娱乐一下.hehe

你可能感兴趣的:(BNU Rugby Football)