#include #include #include #include #include using namespace std; void solve198() { long long B, N; long long MAX = 0; cin >> B >> N; long long ans =1000000000000000000; vector BOX(N); long long val = 0; for (int i = 0; i < N; i++) { cin >> BOX[i]; val += BOX[i]; MAX = max(MAX, BOX[i]); } val = val / N; vector goal(N); for (int i = 0; i < N; i++) { goal[i] = abs(BOX[i] - val); } sort(BOX.begin(), BOX.end()); reverse(BOX.begin(), BOX.end()); sort(goal.begin(), goal.end()); long long tmp = B; int i = 0; while (val != MAX){ B = tmp; long long count = 0; val = goal[0] + i; for (int i = 0; i < N; i++) { B += BOX[i] - val; count += abs(BOX[i] - val); } if (B >= 0){ cout << val << endl; cout << count<