2019-01-28 [UVA-11389]
2019-01-28 本文已影响0人
林锦天
define _CRT_SECURE_NO_DEPRECATE
include<iostream>
include <cstring>
include<algorithm>
using namespace std;
int main()
{
long long n, d, r,z[2000],w[2000],ti;
while (~scanf("%I64d%I64d%I64d", &n, &d, &r) && n)
{ti = 0; memset(z, 0, sizeof(z)); memset(w, 0, sizeof(w));
while (ti < n)
{
cin >> z[ti]; ti++;
}
ti = 0;
while (ti < n)
{
cin >> w[ti]; ti++;
}
sort(z, z + n);
sort(w, w + n);
long long sum = 0;
for (long long i = 0; i < n; i++)
{
if((z[i] + w[n - i-1]) > d)
sum += (z[i] + w[n - i-1])-d;
}
cout << sum * r << endl;
}
}