Cogs 1435. [Usaco] Goldilocks and N cattle

Source: Internet
Author: User

1435. [Usaco] Goldilocks and N cattle

★★☆ input file: milktemp.in output file: milktemp.out Simple comparison
Time limit: 1 s memory limit:

"Title description"

You may have heard the classic story of Goldilocks and 3 bears.

Little-known is that Goldilocks eventually ran a farm. On her farm, she had a barn containing N-head cows (1<=n <= 20000). Unfortunately, her cows are very sensitive to temperature.

The first cow must be within a specified temperature range of a (i). B (i) to feel comfortable; (0<=a (i) <=b (i) <= 1,000,000,000). If the Goldilocks places a thermostat in the barn, if the temperature t<a (i), the cow will be too cold and will produce X units of milk. If she moves the thermostat into this range (A (i) <=t<=b (i)), then the cow will feel comfortable and will produce y units of milk. If she puts the thermostat to the temperature t>b (i), the cow will feel very hot and will produce the z unit of milk. As expected, the value of Y is always greater than X and Z.

Given the optimal range of x, Y, and Z, as well as the temperature of each cow, if Goldilocks set the Barn thermostat best, calculate the maximum number of blonde girls getting milk, known as x, Y and z are integers, range 0. 1000. Thermostats can be set to a value of any integer.

"input Format"

Line 1th: Four integers separated by a space: N X Y Z.

Line 2nd: 1 + N: line 1+i contains two integers separated by spaces: A (i) and B (i).

"Output format"

1 lines: Blonde girl can get the most milk when she sets the best temperature in the barn.

"Sample Input"

4 7 9 65 83 413 207 10

"Sample Output"
31
"Hint"

There are 4 cows on the farm with a temperature range of 5. 8,3. 4,13. 20,10. 7. A cold cow produces 7 units of milk, a comfortable cow produces 9 units of milk, and a hot cow produces 6 units of milk.

"Data Size"

Test data for 50%: n<=5

The remaining 50% of the test data: 10000<n<=20000.

"Source"

Usaco November Contest, Bronze

Translate by CQW

Data from Cstdio

/*The optimal temperature must be obtained at the boundary and then enumerated.*/#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>using namespacestd;intN,x,y,z,ans;intnum1[20010],num2[20010];intMain () {Freopen ("milktemp.in","R", stdin); Freopen ("Milktemp.out","W", stdout); scanf ("%d%d%d%d",&n,&x,&y,&z);  for(intI=1; i<=n;i++) scanf ("%d%d",&num2[i],&Num1[i]); Sort (NUM1+1, num1+1+N); Sort (num2+1, num2+1+N);  for(intI=1; i<=n;i++){        intTmp1=upper_bound (num2+1, num2+1+n,num1[i])-num2;//minimum value greater than cold        intTmp2=lower_bound (num1+1, num1+1+n,num1[i])-num1-1;//maximum value less than heat        if(tmp2>n) tmp2=0; if(tmp1>n) Ans=max (ans,tmp2*z+ (N-TMP2) *y); ElseAns=max (ans,tmp2*z+ (n-tmp1+1) *x+ (tmp1-tmp2-1)*y); TMP1=upper_bound (num2+1, num2+1+n,num2[i])-num2;//minimum value greater than coldTmp2=lower_bound (num1+1, num1+1+n,num2[i])-num1-1;//maximum value less than heat        if(tmp2>n) tmp2=0; if(tmp1>n) Ans=max (ans,tmp2*z+ (N-TMP2) *y); ElseAns=max (ans,tmp2*z+ (n-tmp1+1) *x+ (tmp1-tmp2-1)*y); } cout<<ans;}/*4 787 993 30224514 2725628276 2870213708 1918219192 30394*/
View Code

Cogs 1435. [Usaco] Goldilocks and N cattle

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.