HDU 5461 Largest Point(水)

思路:直接分成两部分考虑,排个序就可以了


#include<bits/stdc++.h>
using namespace std;
#define LL long long
const int maxn = 5*1e6+7;
LL a[maxn];
struct Node
{
	LL w;
	int id;
}a1[maxn],b1[maxn];
bool cmp(Node a,Node b){return a.w>b.w;}

int main()
{
    int T,cas=1;
	scanf("%d",&T);
	while(T--)
	{
		int n;
		LL aa,bb;
		scanf("%d%lld%lld",&n,&aa,&bb);
		for(int i = 1;i<=n;i++)
		{
			scanf("%lld",&a[i]);
            a1[i].w = aa*a[i]*a[i];
			a1[i].id = i;
			b1[i].w = bb*a[i];
			b1[i].id = i;
		}
		sort(a1+1,a1+1+n,cmp);
		sort(b1+1,b1+1+n,cmp);
		if(a1[1].id!=b1[1].id)
		{
			printf("Case #%d: %lld\n",cas++,a1[1].w+b1[1].w);
			continue;
		}
		else
			printf("Case #%d: %lld\n",cas++,max(a1[1].w+b1[2].w,a1[2].w+b1[1].w));
	}
}


Description

Given the sequence   with   integers  . Given the integral coefficients   and  . The fact that select two elements   and  of   and   to maximize the value of  , becomes the largest point.

Input

An positive integer  , indicating there are   test cases. 
For each test case, the first line contains three integers corresponding to   and  . The second line contains   integers   where   for 

The sum of   for all cases would not be larger than  .

Output

The output contains exactly   lines. 
For each test case, you should output the maximum value of  .

Sample Input

2

3 2 1
1 2 3

5 -1 0
-3 -3 0 3 3

Sample Output

Case #1: 20
Case #2: 0


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值