码迷,mamicode.com
首页 > 其他好文 > 详细

bzoj3399[Usaco2009 Mar]Sand Castle城堡*

时间:2016-08-14 09:01:21      阅读:134      评论:0      收藏:0      [点我收藏+]

标签:

bzoj3399[Usaco2009 Mar]Sand Castle城堡

题意:

给个序列a,再给个可变换顺序的序列b,求a变为b的最小代价。a增加一个单位代价为x,降低一个单位代价为y。序列大小≤25000

题解:

a,b排序,直接统计即可。

代码:

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <algorithm>
 4 #define inc(i,j,k) for(int i=j;i<=k;i++)
 5 #define maxn 25010
 6 using namespace std;
 7 
 8 inline int read(){
 9     char ch=getchar(); int f=1,x=0;
10     while(ch<0||ch>9){if(ch==-)f=-1; ch=getchar();}
11     while(ch>=0&&ch<=9)x=x*10+ch-0,ch=getchar();
12     return f*x;
13 }
14 int n,a[maxn],b[maxn],x,y,ans;
15 int main(){
16     n=read(); x=read(); y=read(); inc(i,1,n)a[i]=read(),b[i]=read();
17     sort(a+1,a+n+1); sort(b+1,b+n+1);
18     inc(i,1,n)if(b[i]>a[i])ans+=(b[i]-a[i])*x;else ans+=(a[i]-b[i])*y;
19     printf("%d",ans); return 0;
20 }

 

20160810

bzoj3399[Usaco2009 Mar]Sand Castle城堡*

标签:

原文地址:http://www.cnblogs.com/YuanZiming/p/5769443.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!