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
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.

题目大意:Tommy有n个数,Banban有m个数,Tommy会选择自己的一个数隐藏起来,Banban会选择自己的一个数和Tommy的一个没有隐藏的数相乘,Tommy想让结果最小,Banban想让结果最大,问最后的结果是什么.

分析:这题坑啊.以为只用判断两个端点的情况的,结果没想到有负数.

   这道题的话一个三重循环就能搞定.枚举隐藏哪一个数,将之后所得的乘积排个序,取第二大的就是答案.

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; typedef long long ll; int n,m;
ll a[],b[],c[],tot,ans = ; int main()
{
scanf("%d%d",&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++)
{
tot = ;
for (int j = ; j <= n; j++)
{
if (j == i)
continue;
for (int k = ; k <= m; k++)
c[++tot] = a[j] * b[k];
}
sort(c + ,c + tot + );
ans = min(ans,c[tot]);
}
cout << ans << endl; return ;
}

Codeforces 934.A A Compatible Pair的更多相关文章

  1. Codeforces 934 A.Compatible Pair

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

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

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

  4. A - A Compatible Pair

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

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

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

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

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

  7. Codeforces 934.C A Twisty Movement

    C. A Twisty Movement time limit per test 1 second memory limit per test 256 megabytes input standard ...

  8. A Compatible Pair

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

  9. Codeforces 934.D A Determined Cleanup

    D. A Determined Cleanup time limit per test 1 second memory limit per test 256 megabytes input stand ...

随机推荐

  1. springMVC 面试题整理

    1. springMVC怎么样把某个请求映射到特定的方法上面? 答:直接在方法上面加上注解@RequestMapping,并且在这个注解里面写上要拦截的路径. 2. @RequestMapping注解 ...

  2. Linux编译移植Qt5的环境_Xillinx的ZYNQ平台

    Linux编译Qt环境 2017年的十一假期,足不出户,一个人在教研室里面搞Qt的移植.我手里面有Samsung的CortexA8,Samsung的 CortexA53还有Ti的Sitara系列的AM ...

  3. stdio中牛逼的写法

    用空间换时间的典型 /* * NOTE! This ctype does not handle EOF like the standard C * library is required to. */ ...

  4. C语言进阶——分支语句06

    if分支语句分析: if语句用于根据条件选择执行语句 else不能独立存在且总是与在它之前的最近if相匹配 esle语句后可以连接其他if语句 用法如下: if(condition) { //stat ...

  5. 【转】灰色在PPT中的运用

    一.作为背景   灰色作为背景能够有效烘托其他元素,特别是与白/黑色渐变,效果更好.   1.黑灰渐变,科技感十足 2.纯灰:简单清晰 http://www.behance.net/gallery/N ...

  6. APP开发手记01(app与web的困惑)

    文章链接:http://quke.org/post/app-dev-fragment.html (转载时请注明本文出处及文章链接) 最近在用博客园的wcf服务做博客园的android和ios的app, ...

  7. 微信里经常看到的滑动翻页效果,slide

    上个星期我们的产品姐姐让我帮她写个微信里经常看到的滑动翻页效果,今天抽空写了3个小demo(只写了webkit需要chrome模拟手机看 开启touch事件), 故此写个随笔. 1.demo1,整个大 ...

  8. php导出数据为CSV文件DEMO

    代码示例: private function _download_send_headers($filename) { // disable caching $now = gmdate("D, ...

  9. 每个套接字地址error

    套接字问题 1 netstat -aon|findstr 5037   2 根据pid,查询占用端口的应用,这里的pid为 8672,查询命令如图 3 杀死对应的PID,taskkill /pid 8 ...

  10. jenkins 连接服务器并运行脚本

    1.登录,在系统管理——节点管理——新增节点——配置从节点,添加远程工作目录,选择启动方式:通过JAVA WEB启动代理,添加JDK 2.在列表点节点,点launch下载插件,放到D:\JENKINS ...