image.png
#include<cstdio>
#include<vector>
#include<algorithm>
#include<iostream>
using namespace std;
int main() {
int c, p, ans = 0, m = 0, n = 0;
cin >> c;
vector<int> coupon(c);
for (int i = 0; i < c; i++)
cin >> coupon[i];
cin >> p;
vector<int> values(p);
for (int i = 0; i < p; i++)
cin >> values[i];
sort(coupon.begin(), coupon.end());
sort(values.begin(), values.end());
while (m < c && n < p && coupon[m] < 0 && values[n] < 0) {
ans += coupon[m] * values[n];
m++;
n++;
}
m = c - 1, n = p - 1;
while (m >= 0 && n >= 0 && coupon[m] > 0 && values[n] > 0) {
ans += coupon[m] * values[n];
m--;
n--;
}
cout << ans;
// system("pause");
return 0;
}
网友评论