結果

問題 No.198 キャンディー・ボックス2
ユーザー masa
提出日時 2016-07-20 18:00:21
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 582 bytes
コンパイル時間 579 ms
コンパイル使用メモリ 72,356 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-10-15 17:54:09
合計ジャッジ時間 1,595 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 12 WA * 14
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>

using namespace std;

int main() {
	int b, n;

	cin >> b >> n;
	vector<int> c(n, 0);
	long long total = 0;
	for (int i = 0; i < n; i++) {
		cin >> c[i];
		total += c[i];
	}

	long long ans = 1e18, tmp;
	int avg = total / n;
	for (int i = avg - 1; i <= avg + 1; i++) {
		if (i < 0) {
			continue;
		}

		if (1LL * i * n > total + b) {
			continue;
		}

		tmp = 0;
		for (int j = 0; j < n; j++) {
			tmp += abs(c[j] - i);
		}
		ans = min(ans, tmp);
	}
	cout << ans << endl;
	return 0;
}
0