結果

問題 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
コンパイル時間 790 ms
コンパイル使用メモリ 76,672 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-11-16 09:59:24
合計ジャッジ時間 1,648 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

#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