Logo
(追記) (追記ここまで)

23692번 - Array 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
5 초 (추가 시간 없음) 256 MB369628.571%

문제

Chiaki has an array of integers $a_1,a_2,\dots, a_n$. Chaiki can replace an element $a_x$ to another integer $y$. Let the resulting array be $b_1,b_2,\dots,b_n,ドル Chiaki would like to know the minimum value of $|a_x-y| + \sum\limits_{k=1}^{n} k \cdot c_k,ドル where $c_k$ is the number of distinct integers in $b_1,b_2,\dots,b_k$.

입력

There are multiple test cases. The first line of the input contains an integer $T,ドル indicating the number of test cases. For each test case:

The first line contains an integer $n$ (1ドル \le n \le 10^6$) -- the length of the array.

The second line contains $n$ integers $a_1, a_2, \dots, a_n$ (1ドル \le a_i \le 10^9$).

It is guaranteed that the sum of $n$ in all test cases will not exceed 10ドル^6$.

출력

For each test case, output an integer denoting the answer.

제한

예제 입력 1

1
4
1 2 3 4

예제 출력 1

22

힌트

출처

Contest > Open Cup > 2018/2019 Season > Stage 15: Grand Prix of China A번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /