2015 ACM/ICPC Asia Regional Shenyang Online-1012 Largest Point
Largest Point
Time Limit: 1500/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 0 Accepted Submission(s): 0
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.
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.
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
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
using namespace std;
const long long N=5000010;
int num[N];
typedef struct AA
{
long long f;//儲存ati^2
long long Count;//儲存編號
} A;
A s[N];
typedef struct BB
{
long long ff;//儲存btj
long long ccount;//儲存編號
} B;
B ss[N];
int cmp(const void* x1,const void* y1)//ati^2降序
{
A* x=(A*)x1;
A* y=(A*)y1;
long long m=y->f-x->f;
return m;
}
int com(const void* x1,const void* y1)//btj降序
{
B* x=(B*)x1;
B* y=(B*)y1;
long long m=y->ff-x->ff;
return m;
}
int main()
{
long long c,n,a,b,i,cnt=1;
long long sum;
scanf("%d",&c);
while(c--)
{
sum=0;
scanf("%d%d%d",&n,&a,&b);
for(i=0; i<n; ++i)//輸入處理儲存資料
{
scanf("%d",&num[i]);
s[i].f=a*num[i]*num[i];
ss[i].ff=b*num[i];
s[i].Count=i;
ss[i].ccount=i;
}
qsort(s,n,sizeof(AA),cmp);//排序
qsort(ss,n,sizeof(BB),com);
if(s[0].Count==ss[0].ccount)//如果最大的兩個數編號相同
{
if((s[0].f+ss[1].ff)>(s[1].f+ss[0].ff))
sum=s[0].f+ss[1].ff;
else
sum=s[1].f+ss[0].ff;
}
else
sum=s[0].f+ss[0].ff;
printf("Case #%d: %I64d\n",cnt++,sum);
}
return 0;
}
嗯,所有資料都要用long long。。
相關文章
- The 2021 ICPC Asia Shenyang Regional Contest
- 2017 ACM/ICPC Asia Regional Shenyang Online - 做題記錄ACM
- 2016-2017 ACM-ICPC Asia-Bangkok Regional ContestACM
- 2013 ACM/ICPC Asia Regional Online —— Warmup2 兩個水題ACM
- HDU4998 Rotate (2014 ACM/ICPC Asia Regional Anshan Online)ACM
- 2018-2019 ACM-ICPC, Asia Seoul Regional Contest——A - CircuitsACMUI
- The 2024 ICPC Asia Nanjing Regional ContestNaN
- The 2022 ICPC Asia Nanjing Regional ContestNaN
- The 2023 ICPC Asia Macau Regional ContestMac
- The 2022 ICPC Asia Xian Regional Contest
- The 2022 ICPC Asia Hangzhou Regional Programming Contest
- HDU5023A Corrupt Mayor's Performance Art (2014 ACM/ICPC Asia Regional Guangzhou Online)ORMACM
- The 2022 ICPC Asia Xian Regional Contest 前六題
- 2018 ICPC-ACM shenyang G - Best ACMer Solves the Hardest ProblemACM
- HDU 5052 Yaoge’s maximum profit 光禿禿的樹鏈拆分 2014 ACM/ICPC Asia Regional Shanghai Online...ACMAI
- 2015 ACM/ICPC EC-FinalACM
- 【賽後補題】(HDU6228) Tree {2017-ACM/ICPC Shenyang Onsite}ACM
- The 2022 ICPC Asia Nanjing Regional Contest IGDA,和令人疑惑的MNaN
- The 2023 ICPC Asia Hangzhou Regional Contest (The 2nd Universal Cup. Stage 22: Hangzhou)
- 2017-2018 ACM-ICPC Southeast Regional Contest (Div. 1)ACMAST
- 2017-2018 ACM-ICPC Pacific Northwest Regional Contest (Div. 1)ACM
- 2017-2018 ACM-ICPC, Central Europe Regional Contest (CERC 17)ACM
- Chayas - 2023-2024 ICPC, Asia Yokohama Regional Contest 2023, Problem E
- 2017-2018 ACM-ICPC Southwestern European Regional Programming Contest (SWERC 2017)ACM
- The 2023 ICPC Asia Jinan Regional Contest (The 2nd Universal Cup. Stage 17: Jinan)補題記錄NaN
- 2016-2017 ACM-ICPC Northwestern European Regional Programming Contest (NWERC 2016)ACM
- 2016-2017 ACM-ICPC Southwestern European Regional Programming Contest (SWERC 2016)ACM
- ACM ICPC Vietnam National Second RoundACM
- HDU4091(2011 Asia Shanghai Regional Contest)AI
- acm/icpc入門級演算法模板ACM演算法
- HDU3714 Error Curves(2010 Asia Chengdu Regional Contest)Error
- The 2023 ICPC Asia EC Regionals Online Contest (I)
- The 2024 ICPC Asia East Continent Online Contest (I)AST
- SDNU_ACM_ICPC_2021_Winter_Practice_4th [個人賽]ACM
- ACM創新實驗室代表隊成功闖入ICPC ACM青島區域賽現場賽ACM
- ACM-ICPC 2018 徐州賽區網路預賽ACM
- ACM-ICPC世界冠軍教你如何備戰程式設計競賽ACM程式設計
- ACM-ICPC 2018 瀋陽賽區網路預賽ACM