#GD0000159. Những vách núi thử thách (Challenging Cliffs)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Những vách núi thử thách (Challenging Cliffs)
Challenging Cliffs
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
Arrange all given cliff heights in a line. First minimize the absolute difference between the first and last heights. Subject to that minimum, maximize the number of adjacent pairs satisfying . Output any optimal arrangement.
Input
The first line contains . The second line contains the positive heights.
Output
Print exactly heights forming a permutation of the input multiset and satisfying both optimization objectives.
Subtasks
- Subtask 1 (20 points): ; .
- Subtask 2 (30 points): ; .
- Subtask 3 (50 points): ; .
Examples
Input
4
4 2 1 2
Output
2 4 1 2
Explanation
The order has equal endpoints, yielding the minimum possible endpoint difference . Two adjacent transitions ( and ) are nondecreasing; the remaining transition is not. Three such transitions are impossible under the endpoint condition for this multiset.