DMPG '17 S1 - Molly and Difference

View as PDF

Submit solution


Points: 5 (partial)
Time limit: 2.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

Molly loves subtraction. She also loves non-negative numbers. For her birthday, Molly received an array A_1, A_2, \ldots, 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 = \left|A_i - A_j\right|, such that 1 \le i, j \le N.

Subtasks

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, \ldots, A_N.

Output Specification

The minimum value of d.

Sample Input

5
21 -10 7 3 18

Sample Output

3

Comments


  • -3
    Winbigwok  commented on April 7, 2020, 10:13 a.m.

    its |i - j| >= 0 not i and j >= 0 btw


  • 0
    IanHu  commented on Dec. 9, 2018, 11:17 p.m.

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


    • 2
      kingW3  commented on Dec. 10, 2018, 6:49 a.m.

      Use BufferedReader


      • -2
        IanHu  commented on Dec. 20, 2018, 11:29 p.m.

        Thanks :-)


  • 5
    Kirito  commented on April 25, 2017, 12:05 p.m. edited

    Hint for Python Coders getting TLE: Use PyPy instead.