Largest Point
Time Limit: 1500/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Submission(s): 2100 Accepted Submission(s): 800
Problem Description
Given the sequence
A
with
n
integers
t
1
,t
2
,⋯,t
n![]()
. Given the integral coefficients
a
and
b
. The fact that select two elements
t
i![]()
and
t
j![]()
of
A
and
i≠j
to maximize the value of
at
2
i
+bt
j![]()
, 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×10
6
), a (0≤|a|≤10
6
)
and
b (0≤|b|≤10
6
)
. The second line contains
n
integers
t
1
,t
2
,⋯,t
n![]()
where
0≤|t
i
|≤10
6![]()
for
1≤i≤n
.
The sum of n
for all cases would not be larger than
5×10
6![]()
.
For each test case, the first line contains three integers corresponding to n (2≤n≤5×10
The sum of n
Output
The output contains exactly
T
lines.
For each test case, you should output the maximum value of at
2
i
+bt
j![]()
.
For each test case, you should output the maximum value of at
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
Recommend
题解:嘿嘿嘿。。。暴力居然过了。可能数据有点水吧。。。
AC代码:
#pragma comment(linker, "/STACK:102400000,102400000")
//#include<bits/stdc++.h>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <bitset>
#include <iomanip>
#include <list>
#include <stack>
#include <utility>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
const double eps = 1e-8;
const int INF = 1e9+7;
const ll inf =(1LL<<62) ;
const int MOD = 1e9 + 7;
const ll mod = (1LL<<32);
const int N =1e6+6;
const int M=100010;
const int maxn=1001;
#define mst(a) memset(a, 0, sizeof(a))
#define M_P(x,y) make_pair(x,y)
#define pi acos(-1.0)
#define in freopen("in.txt","r",stdin)
#define rep(i,j,k) for (int i = j; i <= k; i++)
#define per(i,j,k) for (int i = j; i >= k; i--)
#define lson x << 1, l, mid
#define rson x << 1 | 1, mid + 1, r
const int lowbit(int x) { return x&-x; }
//const int lowbit(int x) { return ((x)&((x)^((x)-1))); }
int read(){ int v = 0, f = 1;char c =getchar();
while( c < 48 || 57 < c ){if(c=='-') f = -1;c = getchar();}
while(48 <= c && c <= 57) v = v*10+c-48, c = getchar();
return v*f;}
ll a[5000001];
int main()
{
ll n,c,b;
ll t,m,i,pos;
ll num1,num2;
while (~scanf("%I64d",&t))
{
ll ans=1;
while (t--)
{
scanf("%I64d %I64d %I64d",&n,&c,&b);
m=100000000;
for (i=1;i<=n;i++)scanf("%I64d",&a[i]);
sort(a+1,a+n+1);
for (i=1;i<=n;i++)
{
if (fabs(a[i])<m){
m=fabs(a[i]),pos=i;
}
}
printf("Case #%I64d: ",ans++);
if (c<0&&b<0)
{
if (pos!=1) printf("%I64d\n",c*a[pos]*a[pos]+b*a[1]);
else
{
num1=c*a[1]*a[1]+b*a[2];
num2=c*a[2]*a[2]+b*a[1];
printf("%d\n",max(num1,num2));
}
continue;
}
else if (c>0&&b>0)
{
printf ("%I64d\n",max(max(c*a[n]*a[n]+b*a[n-1], c*a[n-1]*a[n-1]+b*a[n]), c*a[1]*a[1]+b*a[n]));
continue;
}
else if (c>=0&&b<=0)
{
printf ("%I64d\n",max(max(c*a[n]*a[n]+b*a[1], c*a[1]*a[1]+b*a[2]), c*a[2]*a[2]+b*a[1]));
continue;
}
else if (c<=0&&b>=0)
{
if (pos!=n) printf("%I64d\n",c*a[pos]*a[pos]+b*a[n]);
else
{
num1=c*a[n]*a[n]+b*a[n-1];
num2=c*a[n-1]*a[n-1]+b*a[n];
printf("%d\n",max(num1,num2));
}
continue;
}
}
}
return 0;
}