// yukicoder: No.198 キャンディー・ボックス2 // 2019.8.2 bal4u #include #include #if 1 #define gc() getchar_unlocked() #else #define gc() getchar() #endif int in() { // 非負整数の入力 int n = 0, c = gc(); do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0'); return n; } #define ABS(x) ((x)>=0?(x):-(x)) int N; int c[12]; int cmp(const void *a, const void *b) { return *(int *)a - *(int *)b; } int main() { int B, i, a; long long ans, s; B = in(), N = in(), s = 0; for (i = 0; i < N; i++) c[i] = in(), s += c[i]; qsort(c, N, sizeof(int), cmp); a = c[N/2], ans = 0; if ((long long)a*N > s+B) a = (s+B)/N; for (i = 0; i < N; i++) ans += ABS(c[i]-a); printf("%lld\n", ans); return 0; }