DMOPC '14 Contest 6 P2 - Longest Tunnel

View as PDF

Submit solution


Points: 3 (partial)
Time limit: 2.0s
Memory limit: 64M

Author:
Problem type

Simon likes drilling tunnels parallel to the ground. Simon has drilled N horizontal line tunnels. Each tunnel t starts from X_{t_1} and ends at X_{t_2}. What is the length of the longest tunnel that Simon has dug?

Input Specification

The first line of input will contain the single integer N (1 \le N \le 500) .
For each of the next N lines, line t will contain two space-separated integer values X_{t_1} and X_{t_2} (0 \le X_{t_1} < X_{t_2} \le 10^9).

Output Specification

On one line, the length of the longest tunnel.

Sample Input

3
1 8
9 150
0 81

Sample Output

141

Comments


  • -4
    SagarSaha  commented on July 1, 2020, 11:33 p.m.

    what if two tunnels are the same length?


    • 2
      maxcruickshanks  commented on July 2, 2020, 3:34 p.m.

      You only need to find the longest tunnel, so you can choose either tunnel (if they're tied for the maximum length).


      • 0
        0Power10  commented on July 20, 2021, 5:01 p.m.

        indeed, since your printing out the length not which tunnel it is