#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(static_cast(boxes.size()) / 2, std::accumulate(boxes.begin(), boxes.end(), 0)); 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; }