#include #include #include #include #include int main() { int box_num, having_candy_num; std::cin >> having_candy_num >> box_num; std::vector boxes(box_num); for (int i = 0; i < box_num; i++) std::cin >> boxes[i]; std::sort(boxes.begin(), boxes.end()); long long median = boxes[boxes.size() / 2]; long long count = 0; for (int i = median; i >= 0; i--) { long long h = having_candy_num; for (size_t j = 0; j < boxes.size(); j++) { if (boxes[j] > i) { count += boxes[j] - i; h += boxes[j] - i; } else if (boxes[j] < i) { count += i - boxes[j]; h -= i - boxes[j]; } } if (h >= 0)break; count = 0; } std::cout << count << std::endl; return 0; }