Log inSign up
Problems / B014

Lowest and highest water level

100 ptsCases 15Set by dongbinna
Added October 30.
1 solved1 attempted1 submissionssolvers took 1.0 tries on average

Statement

A marine station records the height of the water with a buoy floating on the sea. A record takes the reference line as 0 and is written in millimeters. When the water stands above the reference line, the difference is written as a positive number, and when it stands below the reference line, the difference is written as a negative number. When the water is level with the reference line, it is written as 0.

The station recorded the height of the water N times over the last survey period. The records are kept numbered 1 to N in the order they were measured. The front of the survey report has to carry the lowest value and the highest value among the N records, side by side. These two values show at a glance how far the water rose and fell over the survey period.

Write a program that prints the lowest value and the highest value in that order when the N records are given.

For example, suppose the N=5 records are as in the following table. Records 1 and 5 are times when the water stood below the reference line, and the other three records are times when it stood above it.

Record number12345
Water height-29079096108279372296405-940679

Sweeping from record 1 in order and replacing the lowest value and the highest value seen so far gives the following.

Record being read12345
Lowest value so far-290790-290790-290790-290790-940679
Highest value so far-29079096108279372296405296405

After sweeping all the way to record 5, the lowest value is -940679 from record 5, and the highest value is 296405 from record 4.

ItemRecord numberValue
Lowest value5-940679
Highest value4296405

So the front of the report carries -940679 and 296405 in that order. When N=1 there is only one record, so the lowest value and the highest value come out as the same value.

Input and output examples

Example 1

Input

5
-290790 96108 279372 296405 -940679

Output

-940679 296405

Example 2

Input

1
-685155

Output

-685155 -685155

Example 3

Input

3
855384 239726 901628

Output

239726 901628

Input

  • First the number of records N is given on the first line. N is a natural number from 1 to 100,000.

  • Next the N records are given on the second line in the order they were measured, with a space between them. Each record is an integer from -1,000,000 to 1,000,000. Negative numbers and 0 can be mixed into the records, and the same value can appear more than once.

Output

  • Print the lowest value and the highest value on one line. Write the lowest value first, put one space, and then write the highest value. Leave no space at the end of the line, and break the line there.

Requirements

  • Read the input from standard input and write the answer to standard output
  • The numbers you have to read are N on the first line and the N records on the second line
  • Negative numbers are mixed into the records. Starting from 0 and weighing the records against that gives a wrong answer
  • The output is one line, and the two values are separated by a single space
  • Grading compares the output with the expected value down to the last character
  • You must write a program that reads from standard input and writes to standard output
  • Trailing spaces at the end of a line and blank lines at the end of the output are ignored when grading
  • The languages you can use are Python and JavaScript
  • The memory limit is 256MB. The browser does not measure it, it only states it
  • The time limit is set by measuring the setter's reference solution on the same runtime
  • On this problem you submit code, not a prompt. That code runs in the browser on this device, and all that goes to the server is a fingerprint of the output and the time it took. Whether it is correct is decided by the server. The run time is a number each device reports, so the code and the device details are posted next to it on the leaderboard.
  • There are 15 cases, and 3 of them show the input together with the expected output. The rest are used only when you submit and are not shown on this page.
  • You have to pass all 15 cases to solve this.
Read the requirements carefully before solving. Tampering with the grading to make a submission look like a pass can get you sanctioned if caught. The code you submit is published on the leaderboard along with the result.

Examples

3 public cases. Judging also uses hidden cases. You have to pass all 15 cases to solve this.

Input
Expected output
1
-685155
-685155 -685155
3
855384 239726 901628
239726 901628
5
-290790 96108 279372 296405 -940679
-940679 296405

Solution

Your code runs on this device. Only the fingerprint of the output and the elapsed time go to the server. The server decides whether it is correct.

0 chars1 lineMemory 256MB (recorded only)Reference 15ms

Submitting requires you to log in. Running against the public cases works without one.

You can test with 3 public cases. Submitting runs the hidden cases too.

People who solved this problem

The time shown is the time spent solving. Input reading time is outside the solver's control, so it is excluded. And since each device reports this value itself, we record which device measured it.

1bampal296ms82 charsPythonWindows NT 10.0 / Chrome/156.0.0.0 / 8코어 / 16GB

Log in and you can see the code once you solve this problem.