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. DC 课程内容

  2. java的面向对象 (2013-09-30-163写的日志迁移

    1)面向对象的特征 1. 抽象:(从java方面来说抽象大多数人还是把它作为java中的一种特征来对待) 抽象就是忽略一个主题中与当前目标无关的那些方面,以便更充分地注意与当前目标有关的方面.抽象包括 ...

  3. python爬虫基础11-selenium大全5/8-动作链

    Selenium笔记(5)动作链 本文集链接:https://www.jianshu.com/nb/25338984 简介 一般来说我们与页面的交互可以使用Webelement的方法来进行点击等操作. ...

  4. selenium2截图ScreenShot的使用

    截图是做测试的基本技能,在有BUG的地方,截个图,保留失败的证据,也方便去重现BUG.所以,在自动化的过程中,也要能截图,也要能在我们想要截取的地方去截图,且能在错误产生时,自动的截图. 示例: 脚本 ...

  5. virtual function c++

    之前一直不明白为什么要用虚函数,我只知道这样的规则, Base b = new derived(); b->do(); 调用的是子类的do(): virtue class只是一个虚拟的,调用的是 ...

  6. THUSC2019游记

    Day 0 完全没有明明是最后一次机会的紧张感.大概是滚粗的预兆. 住在西郊.房间好小. 和thupc前一样又有一场cometoj,好像又有小裙子了.upd:改成星空棒棒糖! Day 1 早餐有点棒. ...

  7. luogu2564 [SCOI2009]生日礼物

    排序枚举左端点,则右端点必定不降 #include <algorithm> #include <iostream> #include <cstring> #incl ...

  8. [POJ 1003] Hangover C++解题

        Hangover Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 95164   Accepted: 46128 De ...

  9. Tensorflow 笔记 -- tensorboard 的使用

    Tensorflow 笔记 -- tensorboard 的使用 TensorFlow提供非常方便的可视化命令Tensorboard,先上代码 import tensorflow as tf a = ...

  10. PTA 11-散列1 电话聊天狂人 (25分)

    题目地址 https://pta.patest.cn/pta/test/15/exam/4/question/722 5-14 电话聊天狂人   (25分) 给定大量手机用户通话记录,找出其中通话次数 ...