Enhanced work arrangements (MAGIC and query set)

Source: Internet
Author: User

Description:

John had to work to make money to keep the farm running. He received n jobs, each of which took exactly one day. John started his work on the first day. He could arrange the order of the work as he would. I had to be paid by PI, but it had to be done by the end of day di. The work completed after the deadline is not paid. Please help John plan his daily work so that he can make the most money.

1 ≤ n ≤ 105, 1 ≤ Di, PI ≤ 109 is disgusting in the data range.

 

Problem solving process:

1. I did this during the winter vacation when I was a greedy topic. I remember the greedy strategy, that is, sort the reward P from large to small, and then arrange the work in sequence, (locate the first node without scheduled time from di ). But look at the data range. There can be 2 points.

2. One optimization: Use a father array to save the first vacant position before each time node .. Find the first blank position along the father array each time. Then I submitted it happily, but there are still two points ..

3. If the topic name is "concurrent query set", try to search for the set. The process of "finding the first vacant space along the father array every time" in section 2 is actually to query the get_father of the set .. Then you can use the query set to write. When a location T has been occupied, then merge (t-1, t ). (Note that in order, it must be T's collection connected to the T-1's collection ). Then I submitted it excitedly, but it was still two points ..

4. I looked at the data range again. 1 ≤ Di, and PI ≤ 109. I thought the di range is the same as N .. Then, the father array cannot be so large...

5. I think the idea should be correct, so try to optimize it .. Then we thought that we could discretize Di, sort di in the order first, and then represent the Di-Di-1 with a D [I. (Remove duplicate vertices) and make the ID corresponding to each di. Modify the previous algorithm, each time get_father finds the first vacant K, then d [k] --, if d [k] = 0, then merge (K-1, k ); practice has proved that this method is feasible .. Magic and query set.

 

Enhanced work arrangements (MAGIC and query set)

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.