Bzoj3399: [usaco 2009 Mar] sand castle

Source: Internet
Author: User
3399: [usaco 2009 Mar] sand castle time limit: 3 sec memory limit: 128 MB
Submit: 22 solved: 17
[Submit] [Status] Description John built a castle with sand. like all the walls of the castle, there are also many gunshots in the city wall. The part between the two adjacent gunshots is called the City tooth ". there are N (1 ≤ n ≤ 25000) City teeth on the city wall, each with a height mi. (1 ≤ limit ≤ 100000 ). now John wants to adjust the height of the city tooth to Bi, B2,... in some order ,..., BN (I ≤ Bi ≤100000 ). -John needs X (I ≤ x ≤ 100) for every increase of the height of a unit. John needs y (1 ≤ y ≤ 100) for every reduction of the height of a unit) RMB. ask John how much money he can use at least to achieve his goal. the data guarantee answer cannot exceed 2 ^ 32. input 3 integers n, x, y in the row 1st. from 2nd to n + 1, enter two integers Mi and Bi in each row. minimum output cost. sample input3 6 5
3 1
1 2
1 2 Sample output11hint

 

1 reduction in 1st urban teeth and 1 increase in 2nd urban teeth

 

Source

Silver

Question: after sorting, directly simulate it. Does it seem correct? Code:
 1 #include<cstdio> 2 #include<cstdlib> 3 #include<cmath> 4 #include<cstring> 5 #include<algorithm> 6 #include<iostream> 7 #include<vector> 8 #include<map> 9 #include<set>10 #include<queue>11 #include<string>12 #define inf 100000000013 #define maxn 5000014 #define maxm 500+10015 #define eps 1e-1016 #define ll long long17 #define pa pair<int,int>18 #define for0(i,n) for(int i=0;i<=(n);i++)19 #define for1(i,n) for(int i=1;i<=(n);i++)20 #define for2(i,x,y) for(int i=(x);i<=(y);i++)21 #define for3(i,x,y) for(int i=(x);i>=(y);i--)22 #define mod 100000000723 using namespace std;24 inline int read()25 {26     int x=0,f=1;char ch=getchar();27     while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();}28     while(ch>=‘0‘&&ch<=‘9‘){x=10*x+ch-‘0‘;ch=getchar();}29     return x*f;30 }31 int n,x,y,a[maxn],b[maxn],ans;32 int main()33 {34     freopen("input.txt","r",stdin);35     freopen("output.txt","w",stdout);36     n=read();x=read();y=read();37     for1(i,n)a[i]=read(),b[i]=read();38     sort(a+1,a+n+1);sort(b+1,b+n+1);39     for1(i,n)40      if(a[i]>b[i])ans+=y*(a[i]-b[i]);else ans+=x*(b[i]-a[i]);41     printf("%d\n",ans);42     return 0;43 }
View code

 

Bzoj3399: [usaco 2009 Mar] sand castle

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.