DMOPC '19 Contest 1 P0 - Range Finding

View as PDF

Submit solution


Points: 3
Time limit: 3.0s
C# 1.4s
Java 1.4s
Python 1.4s
Memory limit: 64M
C# 128M
Java 128M
Python 128M

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

You are given N numbers, a_1, a_2, \dots, a_N. Output the range of this list. The range of a list of numbers is the difference between the largest and smallest values in this list.

Constraints

In all tests,
1 \le N \le 1\,000\,000
-10^9 \le a_i \le 10^9

Input Specification

The first line contains one number, N.
The second line contains N spaced integers, a_i, the numbers in this list.

Output Specification

On one line, output the range of the N numbers.

Sample Input

10
9 2 9 6 8 7 1 3 9 6

Sample Output

8

Comments


  • 0
    LucaC  commented on May 4, 2020, 7:48 a.m.

    How do you split the numbers? Sorry, I am really new to this. Thanks!


    • 3
      Togohogo1  commented on May 4, 2020, 12:03 p.m.

      Since you seem to be a python user, you can do the following:

      nums = list(map(int, input().split()))

    • -8
      BamTargetShock  commented on May 4, 2020, 11:05 a.m.

      This comment is hidden due to too much negative feedback. Click here to view it.


  • 0
    chessdongdong  commented on Jan. 31, 2020, 1:22 p.m.

    How do you shorten the memory limit, I can't get lower than 64M, C#


    • 0
      Plasmatic  commented on Jan. 31, 2020, 1:39 p.m.

      Arrays are not required to complete the problem


      • 0
        wleung_bvg  commented on Jan. 31, 2020, 1:52 p.m.

        The main issue is not about arrays, but rather the length of the input. The entire line is read as a string, which is fairly large (around 12 million characters long) and since this string is probably copied a few times, this can easily go over the memory limit (at the time of this post, it is 64MB). The solution is to not actually read the entire string in the input. This can be done with Console.Read() which only reads a single character at a time. You will then have to parse the characters into integers yourself.