A - A Compatible Pair

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

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

#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
long long cmp(long long x,long long y)
{
return x > y;
} int main()
{
long long a[],b[],c[],n,m;
cin >> n >> m;
if(n >= && m <= )
{
for(int i = ;i < n;i++)
cin >> a[i];
for(int i = ;i < m;i++)
cin >> b[i];
sort(a,a + n,cmp);
sort(b,b + m,cmp);
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,cmp);
cout << c[] << endl;
// for(int i = 0;i < n;i++)
// cout << a[i] << " ";
// cout << endl;
// for(int i = 0;i < m;i++)
// cout << b[i] << " ";
}
return ;
}

排除出一个最大值的就ok了

A - A Compatible Pair-biaobiao88的更多相关文章

  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 934 A.Compatible Pair

    http://codeforces.com/contest/934 A. A Compatible Pair   time limit per test 1 second memory limit p ...

  4. CF934A A Compatible Pair

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

  5. A - A Compatible Pair

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

  6. 题解 CF934A 【A Compatible Pair】 ——贪心

    题意: 给定两个数列 \(A\) . \(B\) ,元素个数分别为 \(n\) , \(m\) \((2 \le n,m \le 50)\) .数列中所有元素大小均在 \(-10^{9}\) 到 \( ...

  7. A Compatible Pair

    Description “年”是一个生活在海洋深处的怪物.每年,它都出现在陆地上,吞噬牲畜甚至是人.为了让怪物离开,人们用红色,光线和爆炸的声音填满他们的村庄,所有这些都吓跑了怪物.   小汤米有 n ...

  8. CF934A A Compatible Pair 题解

    Content 有两个数列 \(A\) 和 \(B\),\(A\) 数列里面有 \(n\) 个元素,\(B\) 数列里面有 \(m\) 个元素,现在请从 \(A\) 数列中删除一个数,使得 \(A\) ...

  9. pair queue____多源图广搜

    .简介 class pair ,中文译为对组,可以将两个值视为一个单元.对于map和multimap,就是用pairs来管理value/key的成对元素.任何函数需要回传两个值,也需要pair. 该函 ...

随机推荐

  1. MariaDB设置主从复制

    主从复制包含两个步骤: 在 master 主服务器(组)上的设置,以及在 slave 从属服务器(组)上的设置. 配置主服务器 master 如果没有启用,则需要 激活二进制日志. 给 master ...

  2. 经典的卷积神经网络及其Pytorch代码实现

    1.LeNet LeNet是指LeNet-5,它是第一个成功应用于数字识别的卷积神经网络.在MNIST数据集上,可以达到99.2%的准确率.LeNet-5模型总共有7层,包括两个卷积层,两个池化层,两 ...

  3. udf文件十六进制

    如下为网上找的前辈们的UDF(以做记录) set @a = unhex('7F454C4602010100000000000000000003003E0001000000800A00000000000 ...

  4. 无法解析的外部符号 "void __cdecl cv::imshow

    解决方法: 把编译环境放到其他没有报错的项目上,编译通过.

  5. JS高阶---为什么说JS是单线程执行的???

    大纲: [主体] (1)如何证明JS运行是单线程的? 上述代码执行顺序结果为:fn()→timeout →timeout 接下来对上述代码做下修改 执行结果如右图所示 接下来点击确认,关闭弹框,再往后 ...

  6. EditPlus常用正则表达式

    正则表达式(Regular Expression,在代码中常简写为regex.regexp或RE)是计算机科学的一个概念.正则表达式使用单个字符串来描述.匹配一系列符合某个句法规则的字符串.在很多文本 ...

  7. 201871010136-赵艳强《面向对象程序设计(java)》第十五周学习总结

    201871010136-赵艳强<面向对象程序设计JAVA>第十五周实验总结   项目 内容 这个作业属于哪个课程 https://www.cnblogs.com/nwnu-daizh 这 ...

  8. appium python demo

    #coding=utf-8from appium import webdriverdesired_caps={}desired_caps["platformName"]=" ...

  9. python -m pip install --upgrade pip

    升级pip后报错 TypeError: 'module' object is not callable 原因 存在两个版本的pip 先把原先版本的卸载了: python -m pip uninstal ...

  10. python json解析字符串出错该如何排查问题

    每天写一点,总有一天我这条咸鱼能变得更咸 python中对于字符串转json格式有专门的json库可以操作 #!/usr/bin/env python # -*- coding: utf-8 -*- ...