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. 该函 ...
随机推荐
- 对学Oracle数据库初学者的开场篇
前言:因为项目原因,近期开始学习Oracle数据库.Oracle是目前最流行的数据库之一,功能强大,性能卓越,相对的学习的难度还是不小.我打算将自己的学习过程记录下来,做个积累,方便自己和其他的学习者 ...
- SSM项目中表单分页操作(PageHepler使用)
Maven pom.xml添加依赖 <dependency> <groupId>com.github.pagehelper</groupId> <artifa ...
- CF1168B Good Triple 性质分析_好题
题意翻译 给出01串s,求数对[l,r]个数,使得能找到至少一对[x,k],使1<=x,k<=|s|且l<=x<x+2k<=r且s[x]=s[x+k]=s[x+2k] 题 ...
- eas之设置单元格可编辑
for(int i=0;i<kdtEntrys.getRowCount();i++){ kdtEntrys.getRow(i).getCell("orgUnit").g ...
- apache+php连接数据库
######## 安装APACHE ##############安装apr/usr/src/apache+php/tar xf apr-1.5.2.tar.gzcd apr-1.5.2./config ...
- Apache2.4更改默认根目录并配置虚拟域名
软件环境: 1.virtualbox中安装Ubuntu 16.04-server 2.window7下安装Xshell5 以上安装好后, 1.设置virtualbox网络为桥接网卡,启动Ubuntu. ...
- (25)Spring Boot使用自定义的properties【从零开始学Spring Boot】
spring boot使用application.properties默认了很多配置.但需要自己添加一些配置的时候,我们应该怎么做呢. 若继续在application.properties中添加 如: ...
- mysql deadlock、Lock wait timeout解决和分析
项目上线 线上遇到大量的deadlock 和wait timeout 但是看程序没什么问题 问dba也不能给出很好的解决方案!最终自己去了解mysql锁 以及看mysq锁日志 如果了解mysql锁的机 ...
- LightOJ - 1232 - Coin Change (II)
先上题目: 1232 - Coin Change (II) PDF (English) Statistics Forum Time Limit: 1 second(s) Memory Limit: ...
- uva 704
自己之前的不见了.. 这题是双向广搜即可过.. // Colour Hash (色彩缤纷游戏) // PC/UVa IDs: 110807/704, Popularity: B, Success ra ...