結果

問題 No.198 キャンディー・ボックス2
コンテスト
ユーザー tester58
提出日時 2015-05-12 23:38:37
言語 C++11(廃止可能性あり)
(gcc 13.3.0 + boost 1.89.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 417 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 3,225 ms
コンパイル使用メモリ 70,252 KB
実行使用メモリ 7,720 KB
最終ジャッジ日時 2025-11-26 11:37:39
合計ジャッジ時間 1,420 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>

using namespace std;

int main()
{
	int b, n; cin >> b >> n;
	vector<int> c(n);
	for(int i=0;i<n;++i) cin >> c[i];
	
	sort(c.begin(),c.end());
	const int mxt= (accumulate(c.begin(),c.end(),0LL)+b)/n;
	const int cts = c[n/2] > mxt? mxt: c[n/2];
	long long ans = 0;
	for(auto dt: c) ans += abs(dt - cts);
	cout << ans << endl;
	return 0;
}
0