LARGEST POINT

Given the sequence A with n integers t1 , t2 , …… , tn . Given the integral coefficients a and b. The fact that select two elements ti and tj of A and i ≠ j to maximize the value of becomes the largest point.

 

输入

An positive integer T, indicating there are T test cases. For each test case, the first line contains three integers corresponding to n (2 ≤ n ≤ 5×106 ), a (0 ≤ |a| ≤ 106 ) and b (0 ≤ |b| ≤ 106 ). The second line contains n integers t1 , t2 , …… , tn where 0 ≤ |ti | ≤ 106 for 1 ≤ i ≤ n.
The sum of n for all cases would not be larger than 5 × 106 .

 

输出

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

 

样例输入

2
3 2 1
1 2 3
5 -1 0
-3 -3 0 3 3

 

样例输出

Case #1: 20
Case #2: 0

题意:给定数 n , a, b ,还有接下来的n个ti 的值,求解的最大的值;

分析: 因为 i 和 j 不可以取相等的值,所以将 a t_{i}^{2}b t_{}^{j} 的值分别贪心来求最大的值 ,如果 a t_{i}^{2}b t_{}^{j}最大值中 i 和 j

的下标相等,则就判断第二大

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
#define ll long long int
#define maxn 1000010
typedef struct nodee{
    ll x,y;
}node;
node maze[maxn],num[maxn];
bool check(node u,node v)
{
    return u.y<v.y;
}
int main()
{
    int f,countt=1;
    ll n,a,b,z;
    scanf("%d",&f);
    while(f--){
        scanf("%lld %lld %lld",&n,&a,&b);
        for(int i=0;i<n;i++){
            scanf("%lld",&z);
            maze[i].x=i+1;
            maze[i].y=a*z*z;
            num[i].x=i+1;
            num[i].y=b*z;
        }
        printf("Case #%d: ",countt);
        countt++;

        sort(maze,maze+n,check);
        sort(num,num+n,check);

        if(maze[n-1].x!=num[n-1].x){
            printf("%lld\n",maze[n-1].y+num[n-1].y);
            continue;
        }

        ll sum,ans;
        sum=maze[n-1].y+num[n-2].y;
        ans=maze[n-2].y+num[n-1].y;
        printf("%lld\n",max(sum,ans));
    }


    return 0;
}

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值