1037. Magic Coupon (25)

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
	int nc;
	scanf("%d", &nc);

	int i;
	vector<long long> v[4];
	long long num;

	for(i = 1; i <= nc; i++)
	{
		scanf("%lld", &num);

		if(num < 0)
		{
			v[1].push_back(num);
		}
		else
		{
			v[0].push_back(num);
		}
	}

	int np;
	scanf("%d", &np);

	for(i = 1; i <= np; i++)
	{
		scanf("%lld", &num);

		if(num < 0)
		{
			v[3].push_back(num);
		}
		else
		{
			v[2].push_back(num);
		}
	}

	int size[4];
	for(i = 0; i <= 3; i++)
	{
		size[i] = v[i].size();
		
		if(size[i] > 0)
		{
			sort(v[i].begin(), v[i].end());
		}
	}

	int j;
	long long res = 0;

	for(i = size[0] - 1, j = size[2] - 1; i >= 0 && j >= 0; i--, j--)
	{
		res += v[0][i] * v[2][j];
	}

	for(i = 0, j = 0; i <= size[1] - 1 && j <= size[3] - 1; i++, j++)
	{
		res += v[1][i] * v[3][j];
	}

	printf("%lld\n", res);

	system("pause");
	return 0;
}

 

posted on 2025-11-23 17:03  王景迁  阅读(0)  评论(0)    收藏  举报

导航