DMOPC '14 Contest 5 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


  • 0
    SagarSaha  commented on July 2, 2020, 3:33 a.m.

    what if two tunnels are the same length?


    • 4
      emmettonysko  commented on March 24, 2022, 5:19 p.m.

      down voting so toxic. valid question bro


    • 4
      maxcruickshanks  commented on July 2, 2020, 7: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).


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

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