DMPG '17 S1 - Molly and Difference

View as PDF

Submit solution


Points: 5 (partial)
Time limit: 2.0s
Memory limit: 256M

Author:
Problem type

Molly loves subtraction. She also loves non-negative numbers. For her birthday, Molly received an array A_1, A_2, \dots, A_N of integers. To make up for the fact that you forgot to bring her a present, you decide to tell her the minimum value of d such that d = |A_i-A_j|, such that 1 \le i, j \le N.

Constraints

For all subtasks:

-10^9 \le A_i \le 10^9

Subtask 1 [40%]

2 \le N \le 1\,000

Subtask 2 [60%]

2 \le N \le 10^6

Input Specification

Line 1: An integer, N.
Line 2: N space separated integers, the array A_1, A_2, \dots, A_N.

Output Specification

The minimum value of d.

Sample Input

5
21 -10 7 3 18

Sample Output

3

Comments


  • 1
    IanHu  commented on Dec. 10, 2018, 4:17 a.m.

    what should i do if i keep getting TLE in Batch #3, using JAVA..... Thanks


    • 3
      kingW3  commented on Dec. 10, 2018, 11:49 a.m.

      Use BufferedReader


      • -4
        IanHu  commented on Dec. 21, 2018, 4:29 a.m.

        Thanks :-)


  • 7
    Kirito  commented on April 25, 2017, 4:05 p.m. edited

    Hint for Python Coders getting TLE: Use PyPy instead.