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

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

Beautiful Sequence

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

요약
수열을 재배열해 양쪽 이웃보다 작지 않은 원소의 수를 최대로 만든다.
난이도

보통10점 중 6점

유형
그리디, 정렬, 조합론
정답자
아직 제출이 없습니다

문제

There is a sequence consisting of NN integers. We want to rearrange the integers to make the most beautiful sequence possible. A sequence is more beautiful when there are more members which are not less than their neighbors. The beauty of a sequence is the number of such members.

Write a program that will rearrange a given sequence to make it the most beautiful possible.

For example, if N=6N = 6 and the sequence is 1,1,2,3,3,41, 1, 2, 3, 3, 4, the beauty of the given sequence is 33. However, if we rearrange the sequence to become 2,1,3,3,1,42, 1, 3, 3, 1, 4, then the beauty of the rearranged sequence is 44, which is the maximum possible.

입력

The first line contains an integer TT, the number of test cases (1≤T≤22221 \le T \le 2222). The test cases follow.

The first line of each test case contains an integer NN, the number of elements (1≤N≤300,0001 \le N \le 300\\,000).

The next line contains the elements of the sequence. Each element is an integer between 11 and 10910^9, inclusive.

The sum of NN over all test cases does not exceed 5,000,0005\\,000\\,000.

출력

For each test case, print one line containing an integer: the highest beauty possible after rearrangement.

예제1

  1. 예제 1

    입력
    2
    6
    1 1 2 3 3 4
    5
    1 2 2 3 3
    
    예상 출력
    4
    4