题目大意:
ai,ai+1,ai+2...
变成
bi,bi+1,bi+2..
不计顺序,增加和减少a数组均有代价。
题解:贪心+排序
小的对应小的
代码:
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#define N 25009
#define LL long long
using namespace std; int n,x,y; LL ans; int a[N],b[N]; int main(){
scanf("%d%d%d",&n,&x,&y);
for(int i=;i<=n;i++)scanf("%d%d",&a[i],&b[i]);
sort(a+,a+n+);sort(b+,b+n+);
for(int i=;i<=n;i++){
if(a[i]==b[i])continue;
if(a[i]>b[i])ans+=y*(a[i]-b[i]);
if(b[i]>a[i])ans+=x*(b[i]-a[i]);
}
cout<<ans<<endl;
return ;
}