1037. Magic Coupon (25)

来源:互联网 发布:深圳联合世纪网络 编辑:程序博客网 时间:2024/05/04 05:39

题目:https://www.patest.cn/contests/pat-a-practise/1037

//1037. Magic Coupon (25)#include<cstdio>#include<algorithm>using namespace std;bool cmp(int a, int b){  return a>b;}int main(){  int NC,NP;  int C[100010]={0},P[100010]={0},i=0,j=0;  long long max=0;  scanf("%d",&NC);  for(i=0; i<NC; i++)    scanf("%d",&C[i]);  sort(C,C+NC,cmp);  scanf("%d",&NP);  for(i=0; i<NP; i++)    scanf("%d",&P[i]);  sort(P,P+NP,cmp);  for(i=0,j=0; C[i]>0 && P[j]>0 && i<NC && j<NP; i++,j++)    max += C[i]*P[j];  for(i=NC-1,j=NP-1; C[i]<0 && P[j]<0 && i>=0 && j>=0; i--,j--)    max += C[i]*P[j];  printf("%ld",max);  return 0;}


0 0