아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

A Pivotal Question

시간 제한2초메모리 제한1024 MB

요약
주어진 배열에서 유효한 분할과 양립할 수 있는 피벗 값을 모두 찾고, 없으면 0을 출력한다.
난이도

보통10점 중 6점

유형
누적 합, 배열, 정렬
정답자
아직 제출이 없습니다

문제

Quicksort is a recursive sorting algorithm developed in 1959 by Tony Hoare. One of the major steps in the algorithm is the partition\/ step: given an element pp in the array (the pivot\/ element) rearrange the elements in the array as shown below where all the values in X_LX\_L are ≤p\leq p and all elements in X_RX\_R are >p> p.

Figure A.1 below shows an array before and after it's been partitioned with the pivot element 1313. Note that the elements in X_LX\_L and X_RX\_R are typically not in sorted order and either one of them could be empty.

Figure A.1: An array before and after a partition

How a partition is executed and how a pivot element is selected are fascinating questions but are not of interest to us. What we would like you to do is the following: given an array, determine all the values that could be the pivot value assuming the array has been partitioned, or determine that the array has not been partitioned.

입력

Input starts with a positive integer nn (1≤n≤106)(1\leq n\leq 10^6) denoting the size of the array. Following this are nn positive integers indicating the values in the array. All values are unique and ≤106\leq 10^6.

출력

Output m=m = the number of values in the array that could have served as pivot values to partition the array, followed by the pivot values in the order that they appear in the input. If m>100m > 100 just output the first 100 of these pivot values. Note that a value of m=0m=0 indicates that the array is not partitioned.

예제1

  1. 예제 1

    입력
    10 1 11 8 13 53 20 63 99 79 94
    
    예상 출력
    3 1 13 63