WC '16 Contest 1 S3 - Tricky's Treats

View as PDF

Submit solution


Points: 12 (partial)
Time limit: 1.0s
Memory limit: 64M

Author:
Problem type
Woburn Challenge 2016-17 Round 1 - Senior Division

Oh boy! It's Tricky's favourite time of year, Halloween! He can't wait to put on his awesome dinosaur costume and take a walk around his neighbourhood. Of course, what he's looking forward to the most are the loads of treats his neighbours are sure to give him!

Tricky lives at one end of a long street. There are N (1N105) other houses on the street, with the ith one being Pi (1Pi109) metres away from his own house. No two houses are at the same location. If Tricky visits the ith house and scares its residents with a fearsome dinosaur roar, he's sure to receive Ci (1Ci104) treats from them. Of course, he can only visit each house at most once, though.

Tricky would love to get as many treats as possible, but one thing may stand in his way - time! He absolutely must be home no later than midnight (that's when the real monsters come out). Fortunately, he may be getting quite a head start on his trick-or-treating expedition - he'll be leaving home M (1M43200000) milliseconds before midnight.

Despite his elaborate costume and the potential weight of many treats, Tricky can get around pretty quickly. He can walk down the street in either direction at a rate of 1 metre per millisecond. If he decides to stop at a house along the way to collect its treats, it'll take him T (1T104) milliseconds to do so before he can continue on his way.

Given that Tricky must be back in the safety of his house at the end of the street after no more than M milliseconds of trick-or-treating, how many treats can he possibly end up with, and what's the probability of him developing long-lasting health issues as a result of the following excessive sugar consumption? (Just kidding, he'll be just fine!)

In test cases worth 3/30 of the points, N10 and M2000.
In test cases worth another 6/30 of the points, N500 and M2000.
In test cases worth another 6/30 of the points, N1000.

Input Specification

The first line of input consists of three space-separated integers N, M, and T.
N lines follow, with the ith of these lines consisting of two space-separated integers Pi and Ci (for i=1N).

Output Specification

Output one line consisting of a single integer - the maximum number of treats that you can receive while still returning home by midnight.

Sample Input

Copy
4 2000 500
123 4
400 20
100 5
751 999

Sample Output

Copy
25

Sample Explanation

One optimal strategy is for Tricky to walk to the 2nd house, collect its treats, walk to the 3rd house, collect its treats, and then walk back home. This takes 400+500+300+500+100=1800 milliseconds, and yields a bounty of 20+5=25 treats. If the 4th house were 1 metre closer to Tricky's house, then he would have just enough time to walk straight to it, collect its 999 treats, and make it back home at midnight.


Comments


  • 3
    tappbros  commented on Nov. 28, 2022, 1:44 a.m. edited

    1000 milliseconds * 1 meter per millisecond = 1000 metres per second. Is bro The Flash or something