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

View as PDF

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

Author:
Problem type
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig
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 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 neighbour is located at metres from the origin, and this neighbour's pie contains enough sugar for your Fax to run a distance of 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 metres from the origin . At time , 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 contains .

For each of the next lines, the line will contain and . Also, .

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

• For 2 of the 15 available marks, .
• For an additional 3 of the 15 available marks, .
• For an additional 3 of the 15 available marks, .
• For an additional 3 of the 15 available marks, .

#### Output Specification

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

#### Sample Input 1

2
0 10
-10 10

#### Sample Output 1

20

#### Sample Input 2

2
0 10
11 10

#### Sample Output 2

10

#### Sample Input 3

3
0 2
1 2
-1 2

#### Sample Output 3

6

• commented on Feb. 20, 2017, 3: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?

• commented on Feb. 20, 2017, 3:32 p.m.

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

• commented on Feb. 20, 2017, 1:38 p.m. edit 3

Edit:Nvm

• commented on Feb. 20, 2017, 1:39 p.m.

Yes.

• commented on Feb. 20, 2017, 10:12 a.m.

Sample Input 3 has been added to clear up any confusion.