#include #include #include #include #include using namespace std; void solve198() { long long B, N; 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]; } val = val / N; vector > goal(N); for (int i = 0; i < N; i++) { goal[i] = make_pair(abs(BOX[i] - val),i); } sort(BOX.begin(), BOX.end()); reverse(BOX.begin(), BOX.end()); sort(goal.begin(), goal.end()); long long tmp = B; int i = 0; while (val != BOX[goal[1].second]){ B = tmp; long long count = 0; val = goal[0].first + 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<