Codeforces (441B) Round #252 (Div. 2)

Source: Internet
Author: User

 

There is an orchard with many trees and many fruits on it. Otherwise, the ripe fruit must be collected within two days. Given the number of trees in the orchard and the number of fruits on the tree, the upper limit that workers can collect each day is obtained to find the maximum value that can be collected after this time period.

It is easy to maintain a one-dimensional array of ans []. First, the data is stored in the struct, and then sorted in ascending order by the fruit maturity date ai. The fruit is preferentially included in ans [ai, add more to ans [ai + 1]. If it is greater than the upper limit, it is recorded as the upper limit. The sum of all elements in the array is the answer.

 

# Include

 
  
# Include

  
   
# Include # define MAX_N 3000 using namespace std; struct fruit {int x, y ;}; bool cmp (fruit a, fruit B) {return a. x

   
    
V) ans [a [I]. x] = v; else ans [a [I]. x] + = ans [a [I]. x-1] + a [I]. y-v; ans [a [I]. x-1] = v ;}} int Mans = 0; for (int I = 0; I <= maxi; I ++) Mans + = ans [I]; printf (% d, Mans); return 0 ;}

   

  

 


 

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.