hdu 5461 Largest Point

来源:互联网 发布:chart.js 更新数据 编辑:程序博客网 时间:2024/05/16 23:55

Problem Description
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 at2i+btj, becomes the largest point.

Input
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.

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

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

Source
2015 ACM/ICPC Asia Regional Shenyang Online

Recommend
wange2014

#include<stdio.h>#include<algorithm>#include<string.h>#include<bits/stdc++.h>#define ll long longusing namespace std;struct nana{    long long m,n;}A[500010],B[500010];int cmp(nana a,nana b){    return a.m<b.m;}int main(){    int T;    ll flag=0;    scanf("%d",&T);    while(T--)    {        ll n,a,b,t;        scanf("%lld%lld%lld",&n,&a,&b);        for(ll i=0;i<n;i++)        {            scanf("%lld",&t);            A[i].m=a*t*t;            A[i].n=i;            B[i].m=b*t;            B[i].n=i;        }        sort(A,A+n,cmp);        sort(B,B+n,cmp);        printf("Case #%lld: %lld\n",++flag,(A[n-1].n==B[n-1].n)?(max(A[n-1].m+B[n-2].m,A[n-2].m+B[n-1].m)):(A[n-1].m+B[n-1].m));    }    return 0;}
0 0