标签:
1 #include<iostream> 2 #include<cstring> 3 #include<cstdio> 4 #include<string> 5 #include<cmath> 6 #include<algorithm> 7 using namespace std; 8 #define MAX 1000000 9 __int64 c[MAX+5]; 10 __int64 p[MAX+5]; 11 __int64 nc,np; 12 int main() 13 { 14 //freopen("INPUT.txt", "r", stdin); 15 while(cin>>nc&&nc>=0){ 16 __int64 i=0; 17 for(;i<nc;i++){ 18 scanf("%I64d",&c[i]); 19 } 20 cin>>np; 21 i=0; 22 for(;i<np;i++){ 23 scanf("%I64d",&p[i]); 24 } 25 sort(c,c+nc); 26 sort(p,p+np); 27 i=0; 28 __int64 sum=0; 29 while(c[i]<0&&p[i]<0&&i<nc&&i<np){ 30 sum+=c[i]*p[i]; 31 i++; 32 } 33 __int64 cc=nc-1; 34 __int64 pp=np-1; 35 while(c[cc]>0&&p[pp]>0&&cc>=0&&pp>=0){ 36 sum+=c[cc]*p[pp]; 37 cc--; 38 pp--; 39 } 40 printf("%I64d\n",sum); 41 } 42 return 0; 43 }
标签:
原文地址:http://www.cnblogs.com/Deribs4/p/4271093.html