PAT (Advanced Level) 1037. Magic Coupon (25)

Posted Fighting Heart

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PAT (Advanced Level) 1037. Magic Coupon (25)相关的知识,希望对你有一定的参考价值。

简单题。

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

const int maxn=100000+10;
int n,m;
long long a[maxn];
long long b[maxn];

bool cmp(const long long &a,const long long &b)
{
    return a>b;
}

int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
    scanf("%d",&m);
    for(int i=1;i<=m;i++) scanf("%lld",&b[i]);
    sort(a+1,a+1+n);
    sort(b+1,b+1+m);
    long long ans=0;
    for(int i=1;i<=min(m,n);i++)
    {
        if(a[i]>=0) break;
        if(b[i]>=0) break;
        ans=ans+a[i]*b[i];
    }
    sort(a+1,a+1+n,cmp);
    sort(b+1,b+1+m,cmp);

    for(int i=1;i<=min(m,n);i++)
    {
        if(a[i]<=0) break;
        if(b[i]<=0) break;
        ans=ans+a[i]*b[i];
    }
    printf("%lld\n",ans);
    return 0;
}

 

以上是关于PAT (Advanced Level) 1037. Magic Coupon (25)的主要内容,如果未能解决你的问题,请参考以下文章

PAT (Advanced Level) 1025. PAT Ranking (25)

PAT Advanced Level 1044

PAT Advanced Level 1043

PAT Advanced Level 1079

PAT Advanced Level 1095

PAT Advanced Level 1038