#include #include #include #include #include using namespace std; int main() { int b, n; cin >> b >> n; vector c(n, 0); long long total = 0; for (int i = 0; i < n; i++) { cin >> c[i]; total += c[i]; } long long ans = 1e18, tmp; int avg = total / n; for (int i = avg - 1; i <= avg + 1; i++) { if (i < 0) { continue; } if (1LL * i * n > total + b) { continue; } tmp = 0; for (int j = 0; j < n; j++) { tmp += abs(c[j] - i); } ans = min(ans, tmp); } cout << ans << endl; return 0; }