#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]; long long ave = round(std::accumulate(boxes.begin(), boxes.end(), 0L)) / box_num; long long min = *std::max_element(boxes.begin(), boxes.end()); //for (int i = 0; i < *std::max_element(boxes.begin(), boxes.end()); i++) { long long count = 0; for (size_t j = 0; j < boxes.size(); j++) { if (boxes[j] > ave) { count += boxes[j] - ave; } else if (boxes[j] < ave) { count += ave - boxes[j]; } } //min = std::min(count, min); //if (count >= min)break; //} std::cout << count << std::endl; return 0; }