#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]; if (boxes.size() % 2 == 0) median = boxes[(boxes.size() - 1) / 2]; long long count = 0; for (size_t j = 0; j < boxes.size(); j++) { if (boxes[j] > median) { count += boxes[j] - median; } else if (boxes[j] < median) { count += median - boxes[j]; } } std::cout << count << std::endl; return 0; }