[BAILIAN] hihoCoder Challenge 34 register

Ended

Participants:186

Verdict:Accepted
Submitted:2018-07-15 19:13:47

Lang:G++

Edit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include<iostream>
#include<algorithm>
#define MAXN 100005
#define endl "\n"
#define LL long long
using namespace std;
LL t=1,n,m,ans;
LL a[MAXN],b[MAXN];
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin>>t;
    for(int i1=1;i1<=t;i1++)
    {
        cin>>n>>m;
        for(int i=0;i<n;i++)cin>>a[i];
        for(int i=0;i<m;i++)cin>>b[i];
        sort(a,a+n);
        sort(b,b+m);
        if(a[n-1]<0&&b[0]>0)ans=a[n-2]*b[0];
        else if(a[0]>0&&b[m-1]<0)ans=a[1]*b[m-1];
        else if(a[0]*b[0]>a[n-1]*b[m-1])ans=max(max(a[1]*b[m-1],a[1]*b[0]),max(a[n-1]*b[m-1],a[n-1]*b[0]));
        else ans=max(max(a[0]*b[0],a[0]*b[m-1]),max(a[n-2]*b[0],a[n-2]*b[m-1]));
        cout<<"Case #"<<i1<<": "<<max(ans,a[n-2])<<endl;
        //cout<<ans<<endl;
    }
    return 0;
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX