cf462 A Compatible Pair

本文介绍了一个关于寻找两个集合中能组成最小亮度乘积配对的问题。通过隐藏其中一个集合的一个元素来达到目标,同时考虑了两个参与者的对立策略。

暴力直接找max

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<algorithm>
using namespace std;
typedef long long ll;
#define f(i,l,r) for(int i=l;i<=r;i++)
#define g(i,l,r) for(int i=l;i>=r;i--)
const int maxn 	= 2505;
ll a[maxn],b[maxn],c[maxn];
ll n,m ; 
 
 int main()
 {
 	cin>>n>>m;
 	f(i,1,n)cin>>a[i];
 	f(i,1,m)cin>>b[i];
 	ll ans = -1000001;
 	ll t ;
	f(i,1,n) f(j,1,m)
	{
		if(ans<a[i]*b[j])
		{
			ans=a[i]*b[j];
			t= i;
		}
	}
	ans = -1000001;
	f(i,1,n)
	{
		if(i==t)continue;

		f(j,1,m)
		{
			if(ans<a[i]*b[j])
			{
				ans=a[i]*b[j]; 	 
			}
		}
	} 

	cout<<ans<<endl;

 }
未来的我一定会感谢现在正在成长的我


请使用c++14 ## 题目描述 为了再现那日的彗星,Nana 和 Lily 需要使用特定的数对把一个序列变成另一个序列。 Nana 有一个长度为 $n$ 序列 $a$,Lily 每次可以选择一个下标 $i(1\le i<n)$,然后操作 $a_i\leftarrow x,a_{i+1}\leftarrow y$。 选定的 $1\le x,y\le k$ 需要满足 $f(a_i,a_{i+1})=f(x,y)=1$。Lily 最后需要把 $a$ 变成另一个长度为 $n$ 的序列 $b$。 其中,Nana 将给出一个 $k$ 个点 $m$ 条边的无向图 $G$,**不**保证没有重边和自环,则 $f(x,y)=1$ 当且仅当图上 $x$ 与 $y$ 之间存在连边。需要注意的是,如果有 $x$ 与 $x$ 之间的连边(一个自环)则 $f(x,x)=1$,否则 $f(x,x)=0$。 Lily 并不太关心构造的方案,所以她想让你多组测试询问 $a$ **是否**能变成另一个长度为 $n$ 的序列 $b$。 > “仍牢记我们之间的**约定**,在心中坚守着**秘密**。**若能化作彗星**,是否就能够**再会**呢。” ## 输入格式 每个数据点的开头有三个整数 $m,k,T$。 前 $m$ 行中,第 $i$ 行有两个整数 $x_i,y_i$ 表示第 $i$ 条边连接了 $(x_i,y_i)$。 接下来共 $T$ 组测试。 每组测试输入三行: 第一行一个整数 $n$。 第二行是一个长度为 $n$ 的序列 $a$,其中第 $i$ 个数是 $a_i$。 第三行是一个长度为 $n$ 的序列 $b$,其中第 $i$ 个数是 $b_i$。 ## 输出格式 对于一组测试,只需要输出一行一个字符串,如果能够成功把 $a$ 变成 $b$,输出 `YES`,否则输出 `NO`。 ## 输入输出样例 #1 ### 输入 #1 ``` 1 2 2 1 2 6 1 1 2 1 2 2 2 1 1 2 2 1 2 2 2 1 2 ``` ### 输出 #1 ``` YES NO ``` ## 说明/提示 ### 样例解释 对于第一组样例,我们有如下的操作方式: 1. 选择 $i=2$,序列变成 $[1,2,1,1,2,2]$。 2. 选择 $i=1$,序列变成 $[2,1,1,1,2,2]$。 3. 选择 $i=4$,序列变成 $[2,1,1,2,1,2]$。 4. 选择 $i=5$,序列变成 $[2,1,1,2,2,1]$。 对于第二组样例,显然你无法进行第一次操作。所以无法成功。 ### 数据范围 | Sub | 数据范围 | 特殊性质 |分数| | :---------: | :-----------: | :-----------: | :--: | | $1$ |$n\le 2$|图连通|$25$| | $2$ |$n\le 10^5$|图连通|$25$| | $3$ |$n\le 10^5$|图是森林|$25$| | $4$ |$n\le 10^5$|无|$25$| 本题开启子任务捆绑,你只有通过这个子任务中的所有测试点才能获得这个子任务对应的分数。 对于所有数据,$1\le T\le 10^4,2\le n\le 10^5,\sum n\le 10^6,1\le m\le 3\times 10^5,1\le k\le 2\times 10^5$。 保证 $1\le a_i,b_i,x_i,y_i\le k$。**不**保证图没有重边和自环。
最新发布
11-10
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值