UVA 11389 The Bus Driver Problem(贪心)

#include <iostream>
#include <algorithm> 
using namespace std;
int a[1005],b[1005];
int main(int argc, char *argv[])
{
	int n,d,r,i,j,ans;
	while(cin>>n>>d>>r&&(n+d+r))
	{
		for(i=0;i<n;i++) cin>>a[i];
		for(i=0;i<n;i++) cin>>b[i];
		sort(a,a+n); sort(b,b+n);
		for(ans=i=0;i<n;i++)
		{
			if(a[i]+b[n-i-1]>d) ans+=(a[i]+b[n-1-i]-d)*r;
		}
		cout<<ans<<endl;
	}
	return 0;
}


posted @ 2013-04-01 13:47  xinyuyuanm  阅读(151)  评论(0编辑  收藏  举报