GCJ 2008 round1AA

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

const int maxn = 10000;
int n;
long long a[maxn];
long long b[maxn];

void init()
{
	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);
	for (int i = 0; i != n; ++ i)	b[i] = -b[i];
	sort(a, a+n);
	sort(b, b+n);
	for (int i = 0; i != n; ++ i)	b[i] = -b[i];
	long long ans = 0;
	for (int i = 0; i != n ;++i)	ans += a[i] * b[i];
	printf("%lld\n", ans);
}

int main()
{
	freopen("a.in","r",stdin);
	freopen("a.txt","w",stdout);
	int sb;
	scanf("%d", &sb);
	for (int i = 1; i <= sb; ++ i)
	{
		printf("Case #%d: ", i);
		init();
	}
	return 0;
}
水题

你可能感兴趣的:(GCJ 2008 round1AA)