Move Stone
면접 대비시간 제한1초메모리 제한2048 MB
n x n 격자에 총 n^2개의 돌이 있을 때, 같은 행이나 열로 돌을 옮겨 각 칸에 돌을 하나씩 두는데 필요한 최소 이동 횟수를 구한다.
문제
You are given an grid. Each cell initially contains some number of stones, such that the total number of stones is exactly .
In one move, you may take a single stone and move it to any other cell in the same row or the same column.
Your goal is to minimize the number of moves needed to make each cell contain exactly one stone.
입력
The first line contains an integer , representing the size of the grid.
Followed by lines, the -th of which contains integers, the -th integer represents the number of stones in cell .
출력
Output a single integer, the minimum number of moves required to make each cell contain exactly one stone.
제한
- The initial number of stones is exactly equal to the number of cells on the board.