A - A Compatible Pair-biaobiao88
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
2 2
20 18
2 14
252
5 3
-1 0 1 2 3
-1 0 1
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的更多相关文章
- Codeforces 934.A A Compatible Pair
A. A Compatible Pair time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Codeforces Round #462 (Div. 2) A Compatible Pair
A. A Compatible Pair time limit per test1 second memory limit per test256 megabytes Problem Descript ...
- Codeforces 934 A.Compatible Pair
http://codeforces.com/contest/934 A. A Compatible Pair time limit per test 1 second memory limit p ...
- CF934A A Compatible Pair
A Compatible Pair time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- A - A Compatible Pair
Problem description Nian is a monster which lives deep in the oceans. Once a year, it shows up on th ...
- 题解 CF934A 【A Compatible Pair】 ——贪心
题意: 给定两个数列 \(A\) . \(B\) ,元素个数分别为 \(n\) , \(m\) \((2 \le n,m \le 50)\) .数列中所有元素大小均在 \(-10^{9}\) 到 \( ...
- A Compatible Pair
Description “年”是一个生活在海洋深处的怪物.每年,它都出现在陆地上,吞噬牲畜甚至是人.为了让怪物离开,人们用红色,光线和爆炸的声音填满他们的村庄,所有这些都吓跑了怪物. 小汤米有 n ...
- CF934A A Compatible Pair 题解
Content 有两个数列 \(A\) 和 \(B\),\(A\) 数列里面有 \(n\) 个元素,\(B\) 数列里面有 \(m\) 个元素,现在请从 \(A\) 数列中删除一个数,使得 \(A\) ...
- pair queue____多源图广搜
.简介 class pair ,中文译为对组,可以将两个值视为一个单元.对于map和multimap,就是用pairs来管理value/key的成对元素.任何函数需要回传两个值,也需要pair. 该函 ...
随机推荐
- 其他综合-CentOS 7 搭建模板机
CentOS 7 搭建模板机 [基于此文章的环境]点我快速打开文章 1.修改静态地址 ip a|awk -F '[ /]+' '$NF~/eth0/ {print $3}' cat >/etc/ ...
- AssetBundleMaster_Introduce_EN
This is an integrated solution for building AssetBundles and loading Assets. what it can do is about ...
- [原创]python+beautifulsoup爬取整个网站的仓库列表与仓库详情
from bs4 import BeautifulSoup import requests import os def getdepotdetailcontent(title,url):#爬取每个仓库 ...
- Grafana中mysql作为数据源的配置方法
需求 近期在使用python写一套模拟API请求的监控项目,考虑数据可视化这方面就采用grafana来呈现,下面来看看怎么弄. 数据源准备 首先安装好mysql,将监控的日志数据写入到mysql之中. ...
- 201871010133-赵永军《面向对象程序设计(java)》第十六周学习总结
201871010133-赵永军<面向对象程序设计(java)>第十六周学习总结 项目 内容 这个作业属于哪个课程 https://www.cnblogs.com/nwnu-daizh/ ...
- TensorFlow语法点滴
1. tf.variable_scope生成一个上下文管理器,用于获取已经生成的变量 with tf.variable_scope('pnet'): data = tf.placeholder(tf. ...
- CF1193A Amusement Park
洛谷 CF1193A Amusement Park 洛谷传送门 题目翻译 有一个游乐场有一个好玩的项目:一些有向滑梯可以将游客从一个景点快速.刺激地传送到另一个景点.现在,你要帮游乐场老板来规划一个造 ...
- Leetcode61.旋转链表
链表中的点已经相连,一次旋转操作意味着: 先将链表闭合成环 找到相应的位置断开这个环,确定新的链表头和链表尾 class Solution{ public: ListNode* rotateRight ...
- 【Mybatis】CDATA
忽视内部尖括号那些东西
- Mysql对表中 数据 的操作 DML
上一知识点回顾: mysql的备份: 直接使用navicat进行备份 转储SQL文件:有结构和数据/ 仅结构 两种 需要还原时 单击 数据库名字 运行SQL文件 创建表ctreate 修改表alt ...