1037 Magic Coupon(25 分)

#include
#include
#include
using namespace std;
const int maxn = 1e5 + 10;
int n1,n2, a[maxn], b[maxn], ans;
vectorz1, z2, f1, f2;
bool comp(int x, int y)
{
    return x > y;
}
int main()
{
    scanf("%d", &n1);
    for (int i = 0; i < n1; i++)
    {
        scanf("%d", &a[i]);
    }
    sort(a, a + n1, comp);
    scanf("%d", &n2);
    for (int i = 0; i < n2; i++)
    {
        scanf("%d", &b[i]);
    }
    sort(b, b + n2, comp);
    for (int i = 0; i < min(n1, n2); i++)
    {
        if (a[i] > 0 && b[i] > 0)ans += a[i] * b[i];
        else break;
    }
    for (int i = n1 - 1, j = n2 - 1; i >= 0, j >= 0; i--, j--)
    {
        if (a[i] < 0 && b[j] < 0)ans += a[i] * b[j];
        else break;
    }
    printf("%d", ans);
    return 0;
}

你可能感兴趣的:(1037 Magic Coupon(25 分))