Problem description

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 14from himself.

In the second example, Tommy will hide 3 and Banban will choose 2 from Tommy and 1from himself.

解题思路:题目给的数据很小,暴力枚举即可。题目的意思就是Big Banban从小Tommy的灯笼中选择一盏小Tommy没有钻进的灯笼,和自己的一盏灯笼组合后亮度不是最亮(即乘积的值不是最大),但Big Banban会选择一个组合,其亮度是最亮的(不能选小Tommy钻进的那盏灯笼)。做法:c[i]存放a数组中当前第i盏灯笼和b数组中每盏灯笼组合后的最大亮度(乘积值最大),然后将c数组排序,c[n-1]即为小Tommy不让Big Banban选择的那个最大亮度的组合,但Big Banban可以选择剩下的最大值c[n-2],即为那对灯笼组合的最大亮度。

AC代码:

 #include<bits/stdc++.h>
using namespace std;
typedef long long LL;
int main(){
int n,m;LL a[],b[],c[];
cin>>n>>m;
for(int i=;i<n;++i)cin>>a[i];
for(int i=;i<m;++i)cin>>b[i];
for(int i=;i<n;++i){
c[i]=a[i]*b[];
for(int j=;j<m;++j)
c[i]=max(c[i],a[i]*b[j]);
}
sort(c,c+n);cout<<c[n-]<<endl;
return ;
}

A - A Compatible Pair的更多相关文章

  1. Codeforces 934.A A Compatible Pair

    A. A Compatible Pair time limit per test 1 second memory limit per test 256 megabytes input standard ...

  2. Codeforces Round #462 (Div. 2) A Compatible Pair

    A. A Compatible Pair time limit per test1 second memory limit per test256 megabytes Problem Descript ...

  3. Codeforces 934 A.Compatible Pair

    http://codeforces.com/contest/934 A. A Compatible Pair   time limit per test 1 second memory limit p ...

  4. CF934A A Compatible Pair

    A Compatible Pair time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  5. 题解 CF934A 【A Compatible Pair】 ——贪心

    题意: 给定两个数列 \(A\) . \(B\) ,元素个数分别为 \(n\) , \(m\) \((2 \le n,m \le 50)\) .数列中所有元素大小均在 \(-10^{9}\) 到 \( ...

  6. A Compatible Pair

    Description “年”是一个生活在海洋深处的怪物.每年,它都出现在陆地上,吞噬牲畜甚至是人.为了让怪物离开,人们用红色,光线和爆炸的声音填满他们的村庄,所有这些都吓跑了怪物.   小汤米有 n ...

  7. CF934A A Compatible Pair 题解

    Content 有两个数列 \(A\) 和 \(B\),\(A\) 数列里面有 \(n\) 个元素,\(B\) 数列里面有 \(m\) 个元素,现在请从 \(A\) 数列中删除一个数,使得 \(A\) ...

  8. A - A Compatible Pair-biaobiao88

    A - A Compatible Pair Nian is a monster which lives deep in the oceans. Once a year, it shows up on ...

  9. pair queue____多源图广搜

    .简介 class pair ,中文译为对组,可以将两个值视为一个单元.对于map和multimap,就是用pairs来管理value/key的成对元素.任何函数需要回传两个值,也需要pair. 该函 ...

随机推荐

  1. 通过Static 字段来维护状态是不是一个好主意

    static是申明静态字段.静态方法或者静态类的修饰符.使用static申明的字段属于类型本身而不属于任何字段,声明的类也具有一些特别特性,比如不能实例化,不能继承等.用通俗化的语言来说,static ...

  2. APICloud开发小技巧(二)

    1.apicloud中 json.字符串之间的互转 $api.jsonToStr(ret); $api.strToJson(ret)  2.页面的来回跳转 例如已经打开了一个页面,跳转走,改变数据在跳 ...

  3. mac nwjs入门

    NW.js由node-webkit项目发展而来其实很多东西官网上都有.但是鉴于搜索引擎(百度,google)搜索到的相关文章,让人看的很不明白.所以决定写下此篇文章. 官网:https://nwjs. ...

  4. 【剑指Offer】13、调整数组顺序使奇数位于偶数前面

      题目描述:   输入一个整数数组,实现一个函数来调整该数组中数字的顺序,使得所有的奇数位于数组的前半部分,所有的偶数位于数组的后半部分,并保证奇数和奇数,偶数和偶数之间的相对位置不变.   解题思 ...

  5. 支持移动触摸的jQuery图片Lightbox插件

    简介 这是一款支持移动触摸设备的简洁jQuery图片Lightbox插件.该LightBox插件可以在移动手机和桌面设备中运行,它具有响应式,预加载图片,键盘支持等特点,非常实用.它的特点还有: 响应 ...

  6. EasyUI Messager 消息框点击右上角x无法执行回掉函数解决

    我先声明下,我是改动源码,网上的其他方法我试过了,不行.我是写java后台的,前端也是小白,可能讲的也也不是很清楚. 首先我想到的是在网上找到解决方法,我找到一个方法说在jquery.easyui.m ...

  7. HDU 4456 Crowd

    Crowd Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submi ...

  8. Oleg and Little Ponies

    Oleg and Little Ponies Time limit: 0.9 secondMemory limit: 64 MB Little boy Oleg loves the cartoon M ...

  9. [bzoj3282]Tree_LCT

    Tree bzoj-3282 题目大意:给你n个点m个操作.更改单点权值,加边,删边:查询路径异或和. 注释:$1\le n,m\le 10^5$ 想法:看到了加边删边,果断想到LCT维护.至于路径异 ...

  10. CSS3 timing-function: steps()介绍

    在应用 CSS3 渐变/动画时.有个控制时间的属性 <timing-function>.它的取值中除了经常使用到的三次贝塞尔曲线以外,还有个steps() 函数. steps 函数指定了一 ...