CCC '17 S2 - High Tide, Low Tide

View as PDF

Submit solution


Points: 5
Time limit: 1.0s
Memory limit: 256M

Problem type
Canadian Computing Competition: 2017 Stage 1, Senior #2

Joe Coder is camping near the Bay of Fundy between Nova Scotia and New Brunswick. When he arrived at the bay, he was told that the difference in height between high tide and low tide at the Bay of Fundy was the largest tidal difference in the world. Ever the skeptic, Joe decided to verify this. He chose a reference point and, after learning from the radio when the tides were highest and lowest, he went with a boat to his reference point and measured the depth of the water. Unfortunately, on the last day of his trip, a strong wind scattered his measurements.

Joe has recovered all of his measurements, but they may not be in their original order. Luckily, he remembers some things about his measurements:

  • He started measuring water levels at a low tide, his second measurement was of the water level at high tide, and after that the measurements continued to alternate between low and high tides.
  • All high tide measurements were higher than all low tide measurements.
  • Joe noticed that as time passed, the high tides only became higher and the low tides only became lower.

Given Joe's measurements in no particular order, you must reconstruct the correct order in which the measurements were taken.

Input Specification

The first line contains the integer N (1 \le N \le 100). The next line contains N distinct space-separated positive integers, where each integer is at most 1\,000\,000.

Output Specification

Output the N integers in the unique order that Joe originally took the measurements.

Sample Input

8
10 50 40 7 3 110 90 2

Sample Output

10 40 7 50 3 90 2 110

Explanation for Sample Output

The low tide measurements (in order) were 10, 7, 3, and 2.
The high tide measurements (in order) were 40, 50, 90, and 110.


Comments


  • -19
    roboreport2  commented on Feb. 13, 2024, 9:02 a.m. edited

    This comment is hidden due to too much negative feedback. Show it anyway.


    • 4
      Codename_A  commented on Feb. 13, 2024, 2:31 p.m.

      Don't post your answers here. Also ask for help in the discord.


  • 6
    X_star12321  commented on April 15, 2022, 9:26 p.m. edited

    sorry if this is a dumb question but how should the output be if there are an odd number of tides e.g if the input was 5, then a b c d e where a<b<c<d<e, would the output be a e b d c c?


    • 5
      KevinYangJ8  commented on May 23, 2022, 5:55 p.m. edit 3

      If you haven't figured out: he started with the low tide, so if the number of input is odd, then the median is the low tide. In your case, it should be cdbea


  • 46
    andrewfeng123  commented on Jan. 25, 2019, 4:41 a.m.

    The number of tides can be an odd number, be careful!


  • 5
    Evan_Real  commented on Nov. 8, 2018, 3:07 a.m. edited

    Low tide first...


    • -5
      Haoyun  commented on May 19, 2022, 1:58 p.m.

      This comment is hidden due to too much negative feedback. Show it anyway.


    • 2
      magicalsoup  commented on Nov. 8, 2018, 3:19 a.m.

      then you print the lowest tide at the end