Nian is a monster which lives deep in the oceans. Once a year, it shows up on the land, devouring livestock and even people. In order to keep the monster away, people fill their villages with red colour, light, and cracking noise, all of which frighten the monster out of coming.
Little Tommy has n lanterns and Big Banban has m lanterns. Tommy’s lanterns have brightness a1, a2, …, an, and Banban’s have brightness b1, b2, …, bm respectively.
Tommy intends to hide one of his lanterns, then Banban picks one of Tommy’s non-hidden lanterns and one of his own lanterns to form a pair. The pair’s brightness will be the product of the brightness of two lanterns.
Tommy wants to make the product as small as possible, while Banban tries to make it as large as possible.
You are asked to find the brightness of the chosen pair if both of them choose optimally.
Input
 The first line contains two space-separated integers n and m (2 ≤ n, m ≤ 50).
The second line contains n space-separated integers a1, a2, …, an.
The third line contains m space-separated integers b1, b2, …, bm.
All the integers range from - 109 to 109.
Output
 Print a single integer — the brightness of the chosen pair.
Examples
 Input
 2 2
 20 18
 2 14
 Output
 252
 Input
 5 3
 -1 0 1 2 3
 -1 0 1
 Output
 2
 Note
 In the first example, Tommy will hide 20 and Banban will choose 18 from Tommy and 14 from himself.
In the second example, Tommy will hide 3 and Banban will choose 2 from Tommy and 1 from himself.
题意: A中有n个数,B中有m个数。A中抽一个数与B中抽一个数相乘。A可以去掉一个数。A想让结果最小,B想让结果最大。结果是多少。
 思路: 结果一定是A中最大值或最小值 与 B中最大值最小值的乘积,讨论最小值是因为负数。
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn = 55;
typedef long long ll;
ll a[maxn],b[maxn];
int main()
{
    int n,m;scanf("%d%d",&n,&m);
    for(int i = 1;i <= n;i++)scanf("%lld",&a[i]);
    for(int i = 1;i <= m;i++)scanf("%lld",&b[i]);
    sort(a + 1,a + 1 + n);sort(b + 1,b + 1 + m);
    
    ll tmp1 = max(a[n - 1] * b[m],a[n - 1] * b[1]);
    ll ctmp1 = max(a[1] * b[m],a[1] * b[1]);
    tmp1 = max(tmp1,ctmp1);
    
    ll tmp2 = max(a[2] * b[m],a[2] * b[1]);
    ll ctmp2 = max(a[n] * b[m],a[n] * b[1]);
    tmp2 = max(tmp2,ctmp2);
    
    ll ans = min(tmp1,tmp2);
    printf("%lld\n",ans);
    return 0;
}
 
                   
                   
                   
                   
                             在一个村庄里,为了抵御每年出现的年兽,村民使用红灯笼来驱赶它。小Tommy和大Banban拥有不同亮度的灯笼,他们必须选择一对灯笼,使亮度的乘积尽可能符合他们的目标。
在一个村庄里,为了抵御每年出现的年兽,村民使用红灯笼来驱赶它。小Tommy和大Banban拥有不同亮度的灯笼,他们必须选择一对灯笼,使亮度的乘积尽可能符合他们的目标。
           
       
           
                 
                 
                 
                 
                 
                
               
                 
                 
                 
                 
                
               
                 
                 扫一扫
扫一扫
                     
              
             
                   373
					373
					
 被折叠的  条评论
		 为什么被折叠?
被折叠的  条评论
		 为什么被折叠?
		 
		  到【灌水乐园】发言
到【灌水乐园】发言                                
		 
		 
    
   
    
   
             
            


 
            