RiseOJ는 solved.ac와 제휴 관계가 없습니다. 티어 아이콘 © solved.ac. solved.ac
포럼
USACO0643

Farmer John's Favorite Operation

Platinum IV 플래티넘 IV
난이도
2s
시간 제한
256MB
메모리 제한
0
맞았습니다!!
0
제출 수
0.0%
정답률
레이팅

의견: 0

설명

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.

Problem credits: Chongtian Ma

제약

SCORING

  • Input 2: \(N \le 1000\) and \(M \le 1000\).
  • Input 3: \(N\le 1000\).
  • Inputs 4-5: \(M\le 10^5\).
  • Inputs 6-16: No additional constraints.

Problem credits: Chongtian Ma

입력 형식

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
출력
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]\).

문제 정보

riseoj 작성

출처 올림피아드 > USACO > 2024-2025 > January > Silver

태그

평가 및 의견

Farmer John's Favorite Operation

개요
출제자 난이도 Platinum IV 플래티넘 IV 의견 0 / 50 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

Farmer John's Favorite Operation

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8