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

33505번 - Farmer John's Favorite Operation 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 2048 MB112706965.714%

문제

It is another cold and boring day on Farmer John's farm. To pass the time, Farmer John has invented a fun leisure activity involving performing operations on an integer array.

Farmer John has an array $a$ of $N$ (1ドル \leq N \leq 2 \cdot 10^5$) non-negative integers and an integer $M$ (1ドル \leq M \leq 10^9$). Then, FJ will ask Bessie for an integer $x$. In one operation, FJ can pick an index $i$ and subtract or add 1ドル$ to $a_i$. FJ's boredom value is the minimum number of operations he must perform so that $a_i-x$ is divisible by $M$ for all 1ドル \leq i \leq N$.

Among all possible $x,ドル output FJ's minimum possible boredom value.

입력

The first line contains $T$ (1ドル \leq T \leq 10$), the number of independent test cases to solve.

The first line of each test case contains $N$ and $M$.

The second line of each test case contains $a_1, a_2, ..., a_N$ (0ドル \leq a_i \leq 10^9$).

It is guaranteed that the sum of $N$ over all test cases does not exceed 5ドル \cdot 10^5$.

출력

For each test case, output an integer on a new line containing FJ's minimum possible boredom value among all possible values of $x$.

제한

예제 입력 1

2
5 9
15 12 18 3 8
3 69
1 988244353 998244853

예제 출력 1

10
21

In the first test case, one optimal choice of $x$ is 3ドル$. FJ can perform 10ドル$ operations to make $a = [12, 12, 21, 3, 12]$.

힌트

출처

Olympiad > USA Computing Olympiad > 2024-2025 Season > USACO 2025 January Contest > Silver 2번

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

출처

대학교 대회

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

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