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. 爱她就用python给她画个小心心 ♥(ˆ◡ˆԅ)

    from turtle import * a = Turtle() screensize(400, 300, "blue") setup(width=1300, height=65 ...

  2. MySQL(mariadb)主从复制模式与复制过滤

    在前一篇文章<mysql多实例与复制应用>中只对mysql的复制做了简单的介绍,本篇内容专门介绍一下mysql的复制. MySQL复制 mysql复制是指将主数据库的DDL和DML操作通过 ...

  3. 对于未来学习Linux的决心书,以此为鉴

    学习Linux的决心书 我叫曹佳佳,来自祖国的大西北甘肃庆阳,2016年大专毕业之后从事自己的专业风力发电行业工作了两年多在从事风电行业的过程中越来越感觉到自己的薪资待遇和以后的发展空间越来越小,而且 ...

  4. 如何导入CSV数据 (python3.6.6区别于python2 环境)

    1.python2环境下 2.python3.6.6环境下 如果用python2环境下的代码,在python3.6.6环境下编译会出现以下问题: 错误(1): SyntaxError:Missing ...

  5. urllib使用四--urlencode,urlparse,

    urllib.urlencode 把字典数据转换为URL编码 # -*- coding: cp936 -*- import urllib params = {'score':100,'name':'爬 ...

  6. LoadRunner使用代理远程执行提示找不到“pre_cci.c”文件

    好久没有使用LoadRunner了,工作需要使用一下,执行总是提示找不到“pre_cci.c”文件,找问题花了很长时间终于找到问题了.万事还是需要找到原因: cci 会将 pre_cci.c 文件作为 ...

  7. BitLocker:如何启用网络解锁

    TechNet 库Windows ServerWindows Server 2012 R2 和 Windows Server 2012服务器角色和技术安全和保护BitLockerBitLocker 中 ...

  8. 剑指Offer - 九度1503 - 二叉搜索树与双向链表

    剑指Offer - 九度1503 - 二叉搜索树与双向链表2014-02-05 23:39 题目描述: 输入一棵二叉搜索树,将该二叉搜索树转换成一个排序的双向链表.要求不能创建任何新的结点,只能调整树 ...

  9. 《Cracking the Coding Interview》——第8章:面向对象设计——题目6

    2014-04-23 22:57 题目:实现一个数据结构来表示拼图游戏中的碎片. 解法:一个拼图块儿有四条边,每边只有凹凸平三种情况,当两块碎片拼接的时候,分为四个方向进行,块儿上的图案肯定也是判断是 ...

  10. 如何将现有的项目添加到远程的git库里面!

    我们经常都会遇到这样的场景,就是将本地的一个项目同步到网上远程的git库里面.最近也遇到这样的问题,发现网上很少人讲到这个问题,但是这个问题是很多程序员遇到的版本库管理的最早的拦路虎. 我的远程是ht ...