## CCC '17 S2 - High Tide, Low Tide

View as PDF

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 . The next line contains distinct space-separated positive integers, where each integer is at most .

#### Output Specification

Output the 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 , , , and .
The high tide measurements (in order) were , , , and .

• commented on Feb. 12, 2021, 6:24 p.m.

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

• commented on Feb. 12, 2021, 6:22 p.m.

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

• commented on Feb. 4, 2021, 11:48 a.m.

If anyone completed this question already, can anyone see why I got case 9, 14, 16 wrong? I can't seem to find the issue. Is it simply because my method of solving is wrong?

• commented on Feb. 4, 2021, 12:33 p.m.

Your code does not work with this test case:

5
50 90 60 1 5

round() should not be used for this question - try creating an if else statement that checks if there is an even or odd amount of tides.

• commented on Feb. 4, 2021, 2:58 p.m. edited

Yep, I see the error now. Your suggestion helped me solved the problem.

(Turns out 2.5 will round to 2 in python 3)

• commented on Feb. 4, 2021, 5:16 p.m.

just to prevent misinformation, 2.5 does indeed round to 2 in python 3 - the round function rounds .5's to the nearest even integer.

• commented on Feb. 20, 2019, 9:22 a.m.

Having trouble with 5 of the test cases where my output is starting with high tide instead of low tide as it should. I took the outputted numbers, (assuming that they are the same numbers just in different order) and ran it through my program locally and through online compilers. They are giving me the correct order where output starts with low tide then high tide. Can anyone look at my code and see where I might have gone wrong?

• commented on Sept. 17, 2019, 12:23 a.m.

fixed the issue, whenever it is an odd number, the start and end of your output always need to be low tides, it cannot start and end with high tides

• commented on Sept. 17, 2019, 12:01 a.m.

the same issue with me, I got 5 wrong and all set of numbers worked fine for my outputs, but on here the output shows the high and low tides switched

• commented on Feb. 9, 2019, 10:53 p.m.

Hello, I'm failing a few of the test cases and can't figure out what's wrong. Can someone take a look?

• commented on Jan. 24, 2019, 11:41 p.m.

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

• commented on Nov. 7, 2018, 10:07 p.m. edited

Low tide first...

• commented on Nov. 7, 2018, 10:19 p.m.

then you print the lowest tide at the end