3399: [Usaco2009 Mar]Sand Castle城堡

#include
#include
#include
using namespace std;
inline int read(){
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int n,x,y,a[25001],b[25001];
long long ans;
int main(){
	n=read();x=read();y=read();
	for(int i=1;i<=n;i++)
		a[i]=read(),b[i]=read();
	sort(a+1,a+n+1);
	sort(b+1,b+n+1);
	for(int i=1;i<=n;i++)
		if(b[i]>a[i])ans+=x*(b[i]-a[i]);
			else ans+=y*(a[i]-b[i]);
	printf("%lld",ans);
	return 0;
}

你可能感兴趣的:(3399: [Usaco2009 Mar]Sand Castle城堡)