A - A Compatible Pair
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的更多相关文章
- Codeforces 934.A A Compatible Pair
A. A Compatible Pair time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Codeforces Round #462 (Div. 2) A Compatible Pair
A. A Compatible Pair time limit per test1 second memory limit per test256 megabytes Problem Descript ...
- Codeforces 934 A.Compatible Pair
http://codeforces.com/contest/934 A. A Compatible Pair time limit per test 1 second memory limit p ...
- CF934A A Compatible Pair
A Compatible Pair time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- 题解 CF934A 【A Compatible Pair】 ——贪心
题意: 给定两个数列 \(A\) . \(B\) ,元素个数分别为 \(n\) , \(m\) \((2 \le n,m \le 50)\) .数列中所有元素大小均在 \(-10^{9}\) 到 \( ...
- A Compatible Pair
Description “年”是一个生活在海洋深处的怪物.每年,它都出现在陆地上,吞噬牲畜甚至是人.为了让怪物离开,人们用红色,光线和爆炸的声音填满他们的村庄,所有这些都吓跑了怪物. 小汤米有 n ...
- CF934A A Compatible Pair 题解
Content 有两个数列 \(A\) 和 \(B\),\(A\) 数列里面有 \(n\) 个元素,\(B\) 数列里面有 \(m\) 个元素,现在请从 \(A\) 数列中删除一个数,使得 \(A\) ...
- 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 ...
- pair queue____多源图广搜
.简介 class pair ,中文译为对组,可以将两个值视为一个单元.对于map和multimap,就是用pairs来管理value/key的成对元素.任何函数需要回传两个值,也需要pair. 该函 ...
随机推荐
- Ubuntu下解压(unzip)乱码的解决方法
在Windows上压缩的文件,是以Windows系统默认编码中文来压缩文件.由于zip文件中没有声明其编码,所以linux上的unzip一般以默认编码解压,中文文件名会出现乱码. 通过unzip -- ...
- eas之树
如何设置树的深度(即树总共有几级) // 设置树的深度为3,即树包括0.1.2三级结点 table.getTreeColumn().setDepth(3); 如何设置树的方向 树的方向包括两种:自上向 ...
- 51nod1117 聪明的木匠【贪心+优先队列】
一位老木匠需要将一根长的木棒切成N段.每段的长度分别为L1,L2,......,LN(1 <= L1,L2,-,LN <= 1000,且均为整数)个长度单位.我们认为切割时仅在整数点处切且 ...
- (ccf模拟)201709-2公共钥匙盒
#include <iostream> #include<string> #include <algorithm> #include<sstream> ...
- 2.3 SVN在myeclipse中的使用
一.将svn插件文件夹复制到myeclipse的dropins目录下,并重启myeclipse 二.从SVN中检查项目到myeclipse 2.打开myeclipse,点击window的show v ...
- Solr 6.4.2对比Solr 4.10.3的新特性
1.可以修改时区了.(Solr4.10.3及之前的版本,时区只能是UTC,开发人员需要转换后才能使用.当时为了解决不能设置时区的问题,每个文档都有两个Date,一个是utc时间,一个是utc+8的中国 ...
- asp.net常用容器
autofac就是ioc的第三方的IOC容器 unity也是IOC容器 掌握这两个容器就可以了,非常简单
- iostat -x 1 查看磁盘的IO负载
Linux系统出现了性能问题.一般我们能够通过top.iostat,vmstat等命令来查看初步定位问题.当中iostat能够给我们提供丰富的IO状态数据 $ iostat -x -1 avg-cp ...
- HDU 2717
Catch That Cow Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
- 自己主动化的在程序中显示SVN版本号
有时候会有这种情况,策划拿着应用过来提一个bug,但我们却不好确定策划的手机上装的应用相应的是那个代码版本号. 为了解决问题.我们希望能在应用上显示出当前应用所相应的代码版本号,即svn版本号. 构想 ...