SAC '22 Code Challenge 4 P3 - Obligatory Math Problem

View as PDF

Submit solution


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

Author:
Problem types

Since Max loves setting lazy problems, he starts fiddling with an array of N numbers, A, and finds a problem:

Given an array, minimize i=1N|VAi|, where V is the minimizing value and |ab| denotes the absolute difference between a and b.

Can you solve this lazy problem?

Constraints

Subtask 1 [40%]

1N1000

100Ai100

Subtask 2 [60%]

1N100000

109Ai109

Input Specification

The first line will contain N, the number of elements in the array.

The second line will contain N space-separated integers, the elements of the array, Ai.

Output Specification

Output the V that minimizes the equation i=1N|VAi|.

Note: If there are multiple solutions, any will be accepted.

Sample Input

Copy
6
-5 4 9 -3 2 20

Sample Output

Copy
4

Note that 2 and 3 would also be valid solutions.


Comments

There are no comments at the moment.