TLE '16 Contest 6 (Mock CCC) S3 - Hyper Fax

View as PDF

Submit solution


Points: 15 (partial)
Time limit: 1.0s
Memory limit: 256M

Author:
Problem type
Fax McClad walking his pet Fax in his neighbourhood.

You live in a neighbourhood which is arranged as a straight line.

Your pet Fax is very popular among the N neighbours, so they will feed pies to your pet.

Initially, your Fax is lazy and unable to move, but when he consumes sugar, he becomes hyper and begins to run.

The ith (1iN) neighbour is located at xi metres from the origin, and this neighbour's pie has enough sugar for your Fax to run a distance of di more metres while hyper. The neighbours are extremely kind and enjoy feeding their entire pie to your Fax. The neighbours only have 1 pie each, so your Fax can only eat a neighbour's pie on one visit.

You are the first neighbour, and you are located at 0 metres from the origin (x1=0). At time 0, your pet Fax is located at the origin, and you feed your pie to your Fax.

What is the maximum distance that your Fax can travel while hyper?

Input Specification

The first line will contain N (1N2000).

For each of the next N lines, the ith line will contain xi (109xi109) and di (1di109). Also, x1=0.

No two neighbours share the same xi. The sum of all di will not exceed 109.

  • For 2 of the 15 available marks, xi0.
  • For an additional 3 of the 15 available marks, 100xi100.
  • For an additional 3 of the 15 available marks, N6.
  • For an additional 3 of the 15 available marks, N20.

Output Specification

Output one integer, which is the maximum total distance that your Fax can travel while hyper.

Sample Input 1

Copy
2
0 10
-10 10

Sample Output 1

Copy
20

Sample Input 2

Copy
2
0 10
11 10

Sample Output 2

Copy
10

Sample Input 3

Copy
3
0 2
1 2
-1 2

Sample Output 3

Copy
6

Comments


  • 5
    TheKrishnan  commented on Feb. 20, 2017, 8:28 p.m.

    Does the sugar carry on from neighbour to neighbour? So if not all sugar is used from one neighbour to next, does it carry on?


    • 5
      d  commented on Feb. 20, 2017, 8:32 p.m.

      Yes, all of the previous sugar can still be used up.