結果

問題 No.198 キャンディー・ボックス2
コンテスト
ユーザー ldsyb
提出日時 2016-05-09 09:12:31
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 349 bytes
コンパイル時間 822 ms
コンパイル使用メモリ 73,976 KB
実行使用メモリ 7,720 KB
最終ジャッジ日時 2025-11-26 11:39:38
合計ジャッジ時間 1,845 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;

int main(){
	int b,n;
	cin >> b >> n;
	long long ans = 0,sum = b;
	long long c[n];
	for(int i = 0;i < n;i++){
		cin >> c[i];
		sum += c[i];
	}
	stable_sort(c,c + n);
	int m = min(sum / n,c[n / 2]);
	for(int i = 0;i < n;i++) ans += abs(c[i] - m);
	cout << ans << endl;
}
0