結果
問題 | No.198 キャンディー・ボックス2 |
ユーザー |
![]() |
提出日時 | 2015-05-12 23:38:37 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 1,000 ms |
コード長 | 417 bytes |
コンパイル時間 | 554 ms |
コンパイル使用メモリ | 64,648 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-16 09:03:32 |
合計ジャッジ時間 | 1,462 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 26 |
ソースコード
#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; }