1037. Magic Coupon

#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<queue>
#include<vector>
#include<cmath>
#include<iomanip>
#include<algorithm>
using namespace std;

bool greaterCmp(int a, int b)
{
	return a>b;
}

int main()
{
	int NC,NP,i,j,x;
	vector<int> v1,v2;
	cin>>NC;
	for(i=0; i<NC; i++)
	{
		cin>>x;
		v1.push_back(x);
	}
	cin>>NP;
	for(i=0; i<NP; i++)
	{
		cin>>x;
		v2.push_back(x);
	}
	sort(v1.begin(),v1.end(),greaterCmp);
	sort(v2.begin(),v2.end(),greaterCmp);
	int sum = 0;
	i = 0;
	while(v1[i]>0 && v2[i]>0)
	{
		sum += v1[i]*v2[i];
		i++;
	}
	int h1 = v1.size() - 1;
	int h2 = v2.size() - 1;
	while(h1>=i && h2>=i && v1[h1]<0 && v2[h2]<0)
	{
		sum += v1[h1]*v2[h2];
		h1--;
		h2--;
	}
	cout<<sum<<endl;
	return 0;
}

  

posted @ 2012-12-15 10:38  Frank@609  Views(216)  Comments(0Edit  收藏  举报