“玲珑杯”ACM比赛 Round #13

A题:

输出格式pe了,玲珑oj64位输入%I64d和%lld都可以,输出必须用%lld,不然就会pe

AC代码:

#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
long long a[500010];
long long b[500010];
int main()
{
    int n;
    scanf("%d",&n);
    for (int i=0; i<n; i++)
    {
        scanf("%lld",&a[i]);
    }
    for (int i=0; i<n; i++)
    {
        scanf("%lld",&b[i]);
    }
    sort(a,a+n);
    sort(b,b+n);
    long long sum = 0;
    for (int i=n-1; i>=0; i--)
    {
        //必须用long long 数组存不然中途会造成溢出
        sum += a[i] * b[i];
    }
    printf("%lld\n",sum);
    return 0;
}



发布了477 篇原创文章 · 获赞 34 · 访问量 21万+

猜你喜欢

转载自blog.csdn.net/qq_25605637/article/details/68957489