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. 该函 ...
随机推荐
- win8使用教程
win8如何关机 http://product.pconline.com.cn/itbk/software/win8/1305/3301394.html shutdown.exe -s -t 00 W ...
- [Intermediate Algorithm] - Binary Agents
题目 传入二进制字符串,翻译成英语句子并返回. 二进制字符串是以空格分隔的. 提示 String.charCodeAt() String.fromCharCode() 测试用例 binaryAgent ...
- bzoj 4994: [Usaco2017 Feb]Why Did the Cow Cross the Road III 树状数组_排序
Description 给定长度为2N的序列,1~N各处现过2次,i第一次出现位置记为ai,第二次记为bi,求满足ai<aj<bi<bj的对数 题解: 方法一: 搞一个KDtree, ...
- Spring Cloud Alibaba、Spring Boot、Spring Cloud对应版本关系
Spring Boot Spring Cloud Spring Cloud Alibaba 2.1.x Greenwich 0.9.x 2.0.x Finchley 0.2.x 1.5.x Edgwa ...
- py西游公关之模块
Py西游攻关之模块 模块&包(* * * * *) 模块(modue)的概念: 在计算机程序的开发过程中,随着程序代码越写越多,在一个文件里代码就会越来越长,越来越不容易维护. 为了编写可 ...
- eoLinker-AMS开源版JAVA版本正式发布
eoLinker-AMS开源版JAVA版本正式发布! eoLinker深感广大开发者的支持与厚爱,我们一直在努力为大家提供更多更好的接口服务.截止至2018年4月3日,eoLinker-AMS 开源版 ...
- for 循环的反汇编浅析
for 循环 for 循环是使用频度最高的循环结构,我们通过 C 语言反汇编实例,来分析 for 循环结构在计算机底层的原理和构造.首先,我们编写一个简单的 for 循环: 为了方便观察,我们用十六进 ...
- touch:命令创建文件
touch:创建空文件或改变文件的时间戳属性 [功能说明] touch命令有两个功能:一是创建新的空文件:二是改变已有文件的时间戳属性 [语法格式] touch [option] [file] tou ...
- supervisor---elasticsearch 采坑回顾
supervisor 是一个可以管理进程的软件,并监控进程状态,异常退出时能自动重启.它是通过fork/exec的方式把这些被管理的进程当作supervisor的子进程来启动,这样只要在supervi ...
- 1.Eclipse创建普通java工程
1.创建java工程 2.输入java 工程名 3.编写类