MWC '15 #4 P2: Data Formatting

View as PDF

Submit solution

Points: 5
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

Salarios77 deals with large amounts of numbers on a daily basis. To ensure consistency in his storage of special numbers, he likes following a particular format when possible:

  • a_i \ge a_{i-1} for all even i (ascending order).
  • a_i \le a_{i-1} for all odd i (descending order).

Given some records of N numbers, determine if it is possible to follow the pattern, and if possible output the pattern.

Input Specification

First line contains N, the amount of numbers provided. The second line consists of N spaced integers, which represent a _nth value.

Output Specification

If it is impossible, output: IMPOSSIBLE. If it is possible, output the N integers in order separated by a space.

Sample Input 1

4
1 1 1 1

Sample Output 1

1 1 1 1

Sample Input 2

4
1 3 3 4

Sample Output 2

1 4 3 3

Comments


  • -2
    LeonLiur  commented on July 1, 2020, 11:25 p.m. edit 2

    The problem is a bit confusing but essentially we only look at the output integers'formatting but not the input ones


  • 0
    Cameron  commented on July 18, 2019, 1:52 p.m.

    You might want to consider stating the restrictions for n.


  • -1
    Paradox  commented on Aug. 25, 2017, 7:41 p.m. edited

    Shouldn't it say

    • a_i \ge a_{i-2} for all even i (ascending order).
    • a_i \le a_{i-2} for all odd i (descending order).

  • 4
    richardyi25  commented on April 16, 2016, 12:44 p.m.

    If the input is

    4
    2 4 6 8

    Is the "2" the first term or the zero-th term?


    • 3
      MathBunny123  commented on April 16, 2016, 1:20 p.m.

      Zero-th term. The output would be 2 8 4 6. The even terms would be 2 and 4, while the odd terms would be 8 and 6.


  • 0
    r3mark  commented on April 16, 2016, 12:09 a.m.

    Shouldn't sample output 2 be "1 3 3 4" as this minimizes the difference?


    • 1
      MathBunny123  commented on April 16, 2016, 12:44 a.m.

      In fact you don't need to worry about the differences, just take note at the statement:

      for all even i.


    • 1
      MathBunny123  commented on April 16, 2016, 12:41 a.m.

      Sorry, the problem statement was not clear. The minimized difference must be for every other term, so like: _3_4, ignore the 1 and 3. Same goes for 1_3_. In other words the minimized difference between consecutive odd/even indexed terms only.