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. MVC5+EasyUI+EF6+Linq通用权限系统出炉--登录(2)

    1.输入验证码后 自动识别验证码并登录.

  2. JavaScript小技巧总结

    JavaScript是一种脚本语言: 语法类似于常见的高级语言 脚本语言,不需要编译就可以由解释器直接运行 变量松散定义 面向对象 JSON是一种数据交换格式,而JSONP是JSON的一种使用模式,是 ...

  3. url 传参数时出现中文乱码

    1.前端通过 url 传递参数,但是参数又有中文,在下一个页面接受参数的时候中文会乱码 解决方案为: 定义和用法 decodeURI() 函数可对 encodeURI() 函数编码过的 URI 进行解 ...

  4. day002 计算机基础之 操作系统和编程语言的分类

    &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp今天主要针对计算机基础中的操作系统和编程语言的分类进行了讲解. 操作系统 &nbsp ...

  5. Restrictions.like("字段field","%表达式exp%");

    Restrictions.like("字段field","%表达式exp%");用hql语句就是 from table where field like '%e ...

  6. eas之编辑表单元格

    --指定表列行单元不可编辑 // 锁定表格.行.列.单元 table.getStyleAttributes().getProtection().setLocked(true); row.getStyl ...

  7. 【剑指Offer】1、二维数组中的查找

      题目描述:   在一个二维数组中(每个一维数组的长度相同),每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序.请完成一个函数,输入这样的一个二维数组和一个整数,判断数组中是否 ...

  8. Java8自定义条件让集合分组

    /** * 将一个指定类型对象的集合按照自定义的一个操作分组: 每组对应一个List.最终返回结果类型是:List<List<T>> * * @param <T> ...

  9. <a>标签中的href伪协议 标签: html 2016-12-24 22:38 365人阅读 评论(0)

    <a id="jsPswEdit" class="set-item" href="javascript:;">修改密码</ ...

  10. win7的目录和vbox的共享,linux中没有权限打开

    来自于 http://www.cnblogs.com/usegear/p/5120427.html win7的目录由vbox共享是个老话题.稳拿网上很多介绍. 在linux中通过文件夹不能打开,说没有 ...