#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 = std::min(boxes[box_num / 2], (std::accumulate(boxes.begin(), boxes.end(), 0LL) + having_candy_num) / box_num); long long count = 0; long long h = having_candy_num; for (size_t j = 0; j < boxes.size(); j++) { count += abs(boxes[j] - median); } std::cout << count << std::endl; return 0; }