#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
using namespace std;
class CA
{
public:
enum{N=100000};
void run();
int clist[N],plist[N],nc,np;
};
void CA::run()
{
int i,t,maxback=0;
scanf("%d",&nc);
for(i=0;i<nc;i++)
{
scanf("%d",&clist[i]);
}
scanf("%d",&np);
for(i=0;i<np;i++)
{
scanf("%d",&plist[i]);
}
int ic,ip;
sort(clist,clist+nc);
sort(plist,plist+np);
for(ic=0,ip=0;ic<nc&&ip<np&&clist[ic]<0&&plist[ip]<0;ic++,ip++)
{
maxback+=clist[ic]*plist[ip];
}
for(ic=nc-1,ip=np-1;ic>=0&&ip>=0&&clist[ic]>0&&plist[ip]>0;ic--,ip--)
{
maxback+=clist[ic]*plist[ip];
}
cout<<maxback<<endl;
}
int main()
{
// freopen("test.in","r",stdin);
CA *a=new CA;
a->run();
return 0;
}
1037. Magic Coupon (25)
最新推荐文章于 2022-03-12 15:25:38 发布