#BS0000152. Giấc mộng đêm hè (A mid-summer night’s dream)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Giấc mộng đêm hè (A mid-summer night’s dream)
A mid-summer night’s dream
Source: UVa
Version: Phuoc Hung OJ Extended
Problem Statement
A scientist dreams of nonnegative integers . He needs an integer minimizing the total absolute deviation:
Several integers may achieve the minimum. Find the smallest such , the number of input occurrences whose values are optimal choices for , and the number of distinct optimal integer values, including values absent from the input.
Input
- The first line contains .
- The next line contains exactly nonnegative integers .
Output
Print three space-separated integers: the smallest optimal , the number of input elements whose values are optimal, and the number of distinct optimal integer values.
Subtasks
- Subtask 1 (20 points): ; for every .
- Subtask 2 (30 points): ; for every .
- Subtask 3 (50 points): ; for every .
Examples
Example 1
Input
4
1 3 5 8
Output
3 2 3
Explanation
Sorted numbers are with central values and . Every integer yields total distance , while going outside this interval increases it. The three valid integers are , but only and appear in the input, with two occurrences total. The smallest choice is ; print 3 2 3.
Example 2
Input
2
10 10
Output
10 2 1
Explanation
Both numbers equal . Choosing gives zero total distance, which is minimal. Both input occurrences equal this optimal value, and no other integer produces a zero total. Hence print 10 2 1.