結果
問題 | No.198 キャンディー・ボックス2 |
ユーザー |
|
提出日時 | 2015-04-29 01:00:56 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 578 bytes |
コンパイル時間 | 478 ms |
コンパイル使用メモリ | 61,404 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-05 16:06:39 |
合計ジャッジ時間 | 1,338 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 10 WA * 16 |
ソースコード
#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 (avg * 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; }