Lang:G++
Edit12345678910111213141516171819202122232425262728293031#include <bits/stdc++.h>using namespace std;typedef long long ll;const int MAX_N = 1e5 + 5;ll a[MAX_N], b[MAX_N];int main() {int T, n, m;scanf("%d", &T);for (int _ = 1; _ <= T; _++) {scanf("%d%d", &n, &m);for (int i = 0; i < n; i++) scanf("%lld", &a[i]);for (int i = 0; i < m; i++) scanf("%lld", &b[i]);ll bmax = -1e9 - 7, bmin = 1e9 + 7;for (int i = 0; i < m; i++) {bmax = max(bmax, b[i]);bmin = min(bmin, b[i]);}ll scoremax = -1e18 - 7, secondmax = -1e18 - 7;for (int i = 0; i < n; i++) {ll tmp;if (a[i] >= 0) tmp = max(a[i], a[i] * bmax);else tmp = max(a[i], a[i] * bmin);if (tmp >= scoremax) {secondmax = scoremax;scoremax = tmp;}else if (tmp >= secondmax) secondmax = tmp;}printf("Case #%d: %lld\n", _, secondmax);}return 0;