A. A Compatible Pair

time limit per test1 second

memory limit per test256 megabytes

Problem Description

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.


解题心得:

  1. 题意很简单就是给你两个数列a和b,要求你在a中选一个数b中选一个数两数的乘积最大,但是a为了使乘积尽量小会删去一个数,要求你输出除a删去了那个数之后能够的到的乘积最大的那个数。
  2. 数据范围很小也就50,可以先找出乘积最大的z中的那个数,然后标记,在找标记之后最大的就行了。暴力最稳妥。

代码写得很烂,切勿模仿

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 55;
ll n,m;
ll a[maxn],b[maxn];
map <ll,ll> maps;
struct NODE{
ll x,y,va;
friend bool operator < (const NODE a,const NODE b){
return a.va < b.va;
}
};
int main() {
priority_queue <NODE> qu;
scanf("%lld%lld", &n, &m);
for (int i = 0; i < n; i++)
scanf("%lld", &a[i]);
for (int i = 0; i < m; i++)
scanf("%lld", &b[i]);
for(int i=0;i<n;i++)
for(int j=0;j<m;j++){
NODE temp;
long long c = a[i]*b[j];
temp.x = i;
temp.y = j;
temp.va = c;
qu.push(temp);
}
bool flag = false;
while(!qu.empty()){
NODE temp = qu.top();
qu.pop();
if(!flag){
maps[temp.x] = 233;
flag = true;
}
if(maps[temp.x] != 233){
printf("%lld",temp.va);
break;
}
}
return 0;
}

Codeforces Round #462 (Div. 2) A Compatible Pair的更多相关文章

  1. Codeforces Round #188 (Div. 2) C. Perfect Pair 数学

    B. Strings of Power Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/318/p ...

  2. Codeforces Round #462 (Div. 2) B-A Prosperous Lot

    B. A Prosperous Lot time limit per test 1 second memory limit per test 256 megabytes input standard ...

  3. Codeforces Round #462 (Div. 2), problem: (C) A Twisty Movement (求可以转一次区间的不递增子序列元素只有1,2)

    题目意思: 给长度为n(n<=2000)的数字串,数字只能为1或者2,可以将其中一段区间[l,r]翻转,求翻转后的最长非递减子序列长度. 题解:求出1的前缀和,2的后缀和,以及区间[i,j]的最 ...

  4. Codeforces Round #462 (Div. 2) C DP

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

  5. Codeforces Round #462 (Div. 2)

    这是我打的第三场cf,个人的表现还是有点不成熟.暴露出了我的一些问题. 先打开A题,大概3min看懂题意+一小会儿的思考后开始码代码.一开始想着贪心地只取两个端点的值就好了,正准备交的时候回想起上次A ...

  6. Codeforces Round #462 (Div. 2) D. A Determined Cleanup

    D. A Determined Cleanup time limit per test1 second memory limit per test256 megabytes Problem Descr ...

  7. Codeforces Round #462 (Div. 2) C. A Twisty Movement

    C. A Twisty Movement time limit per test1 second memory limit per test256 megabytes Problem Descript ...

  8. 【Codeforces Round #462 (Div. 1) B】A Determined Cleanup

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 设\(设f(x)=a_d*x^{d}+a_{d-1}*x^{d-1}+...+a_1*x+a_0\) 用它去除x+k 用多项式除法除 ...

  9. 【Codeforces Round #462 (Div. 1) A】 A Twisty Movement

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] ans初值值为a[1..n]中1的个数. 接下来考虑以2为结尾的最长上升子序列的个数. 枚举中间点i. 计算1..i-1中1的个数c ...

随机推荐

  1. <s:property>的用法

    1,访问Action值栈中的普通属性: <s:property value="attrName"/> 2,访问Action值栈中的对象属性(要有get set方法):  ...

  2. 关于@webFilter使用@Order无效问题

    前言 在SpringBoot系列文章的<第七章:过滤器.监听器.拦截器>中,小技巧中指出,可使用@Order设置过滤器的执行顺序.由于没有自己求证过,看了相关材料后,想当然的写进了文章中, ...

  3. Promise 用es5的基础实现

    只实现 then 和 catch function promise(fn) { var state = 'pending'; // 声明函数 var nowResolve = function (ar ...

  4. java获得文件扩展名

    java获得文件扩展名: public static void main(String[] args) throws Exception { String name = ""; S ...

  5. GitHub上易于高效开发的Android开源项目TOP20--适合新手

    1. android-async-http android-async-http是Android上的一个异步.基于回调的HTTP客户端开发包,建立在Apache的HttpClient库上. 2. an ...

  6. websocket的加密和解密

    补充个小知识点:按位与运算 按位与运算是同位都为1才为1,有一个不为1就是0 websocket_hand import socket, base64, hashlib import websocke ...

  7. springBoot 定时器任务

    1.新建一个计划任务类(只能和主类平级或在主类的下级) import java.text.SimpleDateFormat; import java.util.Date; import org.slf ...

  8. 运用CSS3媒体查询判断iPhoneX、iPhoneXR、iPhoneXS MAX及横竖屏

    //iphoneX.iphoneXs @media only screen and (device-width: 375px) and (device-height: 812px) and (-web ...

  9. 绿盟堡垒机云服务(vSAS-H)

    绿盟堡垒机云服务(vSAS-H) 平台: linux 类型: 虚拟机镜像 软件包: basic software devops nsfocus security 堡垒机 服务优惠价: 按服务商许可协议 ...

  10. cms-登陆

    先介绍下登陆的思路: 1.在登陆页面首先前端验证用户名和密码是否正确,如果验证通过,则ajax的方式向后台提交数据. 2.在controller层,将得到的用户名名和密码封装进shiro的token, ...