题解 CF934A 【A Compatible Pair】
其实原本是想用贪心去做的,但是因为涉及到负数乘法,麻烦一些,只好暴力了
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
bool cmp(int x, int y)
{
return x > y;
}
bool cmp2(int x, int y)
{
return x < y;
}
long long a[55], b[55];
int main()
{
long long n, m, cnt = 0, cnt2 = 0, max = -0x7fffffffffffffff, ans = 0x7fffffffffffffff;//无穷大和无穷小
cin >> n >> m;
for(int i = 1; i <= n; i++)
{
cin >> a[i];
}
for(int i = 1; i <= m; i++)
{
cin >> b[i];
}
for(int i = 1; i <= n; i++)
{
max = -0x7fffffffffffffff;
for(int j = 1; j <= n; j++)
{
if(i != j)
{
for(int x = 1; x <= m; x++)
{
max = a[j] * b[x] > max ? a[j] * b[x] : max;
}
}
}
ans = max < ans ? max : ans;
}
cout << ans << endl;
return 0;
}

浙公网安备 33010602011771号