DMOPC '14 Contest 8 P2 - Tides

View as PDF

Submit solution

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

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

Tusk has been stranded on an island for some time now, and it's fair to say that he's grown terribly bored. As such, he's started to find ordinary things immensely fascinating.

Today, he's interested in the waves he sees. He notes that certain times of the day, the water level either increases or decreases. Realizing this phenomenon is due to tides, he is now most fervent about determining the difference in water level between high tide and low tide.

To this end, he's measured the water level N times throughout the day using a high-precision measuring device such that each reading is a unique integer in the range 1 \ldots 10\,000 inclusive.

He knows that after measuring the absolute minimum reading at low tide, the transition to the absolute maximum reading representing the water level at high tide consists of a strictly increasing sequence of water level readings. He's interested in the difference between the absolute maximum and absolute minimum readings: the water level difference between tides.

It's possible that he made a mistake in writing down these readings, however, in which case the sequence between the low tide reading and high tide reading will not be strictly increasing. If this is the case, it's likely that the data is useless — the water level difference cannot be accurately determined — and should be scrapped.

Input Specification

The first line will contain the single integer N (3 \le N \le 1\,000). The second line will contain N space-separated positive integers: the water level readings in chronological order.

Output Specification

The integer difference in water level between high tide and low tide. If the difference cannot be accurately determined, output unknown.

Sample Input 1

2 1 3 5 10

Sample Output 1


Sample Input 2

1 2 5 4 9

Sample Output 2



  • 1
    Angelo_yuan99  commented on July 14, 2020, 4:55 p.m.

    I'm unsure of why my code is wrong, could someone help me?

    • 2
      Jonathan_Uy  commented on July 15, 2020, 7:03 a.m.

      It's possible that the lowest tide occurs after the highest tide. In this case, the difference cannot be accurately determined and you should output unknown.

  • 0
    raytonlin1  commented on April 2, 2018, 4:16 p.m.

    I don't understand if I'm missing a possible case with my python code?

  • 0
    Asuna_Orz  commented on July 20, 2015, 8:52 a.m.

    what will be the result for 2 1 5 10 7 10

    • 2
      d  commented on July 20, 2015, 10:46 a.m.

      All of the readings are unique, so this won't be a test case.