http://codeforces.com/contest/934

A. A Compatible Pair
 
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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

Copy
2 2
20 18
2 14
output
252
input

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

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

代码:

 //A
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<queue>
using namespace std;
typedef long long ll;
const int maxn=+;
ll a[maxn],b[maxn];
int main(){
ll n,m,mx;
int ok;
while(~scanf("%lld%lld",&n,&m)){
for(int i=;i<=n;i++)
scanf("%lld",&a[i]);
for(int i=;i<=m;i++)
scanf("%lld",&b[i]);
mx=-1LL<<;
for(int i=;i<=n;i++){
for(int j=;j<=m;j++){
if(a[i]*b[j]>=mx)
mx=a[i]*b[j],ok=i;
}
}
mx=-1LL<<;
for(int i=;i<=n;i++){
for(int j=;j<=m;j++){
if(a[i]*b[j]>=mx&&ok!=i)mx=a[i]*b[j];
}
}
printf("%lld\n",mx);
}
return ;
}
 

Codeforces 934 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 317]A. Perfect Pair

    [codeforces 317]A. Perfect Pair 试题描述 Let us call a pair of integer numbers m-perfect, if at least on ...

  4. CF934A A Compatible Pair

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

  5. CodeForces - 93B(贪心+vector<pair<int,double> >+double 的精度操作

    题目链接:http://codeforces.com/problemset/problem/93/B B. End of Exams time limit per test 1 second memo ...

  6. Codeforces 165 E. Compatible Numbers【子集前缀和】

    LINK 题目大意 给你一个数组,问你数组中的每个数是否可以在数组里面找到一个数和他and起来是0,如果可以就输出这个数,否则就输出-1 思路 首先很显然的是可以考虑找到每个数每一位都取反的数的子集 ...

  7. A - A Compatible Pair

    Problem description Nian is a monster which lives deep in the oceans. Once a year, it shows up on th ...

  8. Codeforces 934 最长不递减子序列 多项式系数推导

    A B C 给你一个长度为N的01串 你可以翻转一次任意[L,R]的区间 问你最长的不递减序列为多少长 处理出1的前缀和 和2的后缀和 然后N^2 DP 处理出 [L,R]区间的最长不递增序列 #in ...

  9. Codeforces 164 E Compatible Numbers

    主题链接~~> 做题情绪:好题,做拉的比赛的时候想了非常久,想到枚举变幻某一位的 0 为 1 .可是每一个数都这样枚举岂不超时的节奏,当时没想到事实上从大到小枚举一次就 ok 了. 解题思路: ...

随机推荐

  1. phpExcel使用方法二

    require_once './phpexcel/PHPExcel.php'; // 首先创建一个新的对象 PHPExcel object $objPHPExcel = new PHPExcel(); ...

  2. Java求字符串中出现次数最多的字符

    Java求字符串中出现次数最多的字符  [尊重原创,转载请注明出处]http://blog.csdn.net/guyuealian/article/details/51933611      Java ...

  3. Python9-事件及队列-day37

    信号量 from multiprocessing import Process from multiprocessing import Semaphore import time import ran ...

  4. Cleaning Shifts POJ - 2376 (贪心题)

    Cleaning Shifts Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 31194   Accepted: 7677 ...

  5. HDU:1251-统计难题(字典树模板,动态建树,静态建树)

    传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1251 统计难题 Time Limit: 4000/2000 MS (Java/Others) Memor ...

  6. Java技术——Java中创建对象的5种方式

    此文为译文 原文连接:https://dzone.com/articles/5-different-ways-to-create-objects-in-java-with-ex 0. 前言 作为Jav ...

  7. c++ dll 创建

    建立一个C++的Win32DLL,这里要注意选择"Export symbols"导出符号.点击完成. 如下图所示:   由于项目的名称是"TestCPPDLL" ...

  8. [python工具][2]sublime的快捷键

    十.Sublime Text 快捷键列表 快捷键按类型分列如下: 1.通用  ↑↓← →    上下左右移动光标 Alt    调出菜单 Ctrl + Shift + P    调出命令板(Comma ...

  9. Ruby 符号【转】

    Ruby的符号足以让很多初学者迷惑上一段时间,看过本章节后,或许会解开你心中的疑惑. 在Ruby中,一个符号是就是一个Symbol类的实例,它的语法是在通常的变量名前加一个冒号,如 :my_sy Ru ...

  10. AWK 用法

     awk 用法:awk ' pattern {action} ' 变量名 含义 ARGC 命令行变元个数 ARGV 命令行变元数组 FILENAME 当前输入文件名 FNR 当前文件中的记录号 FS ...