結果
問題 | No.198 キャンディー・ボックス2 |
ユーザー |
|
提出日時 | 2022-10-10 00:30:47 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 32 ms / 1,000 ms |
コード長 | 491 bytes |
コンパイル時間 | 2,172 ms |
コンパイル使用メモリ | 199,092 KB |
最終ジャッジ日時 | 2025-02-08 00:53:20 |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 26 |
ソースコード
#include <bits/stdc++.h> #define rep(i,n) for(int i = 0; i < (n); i++) using namespace std; typedef long long ll; int main(){ cin.tie(0); ios::sync_with_stdio(0); ll B,N; cin >> B >> N; vector<ll> C(N); rep(i,N) cin >> C[i]; sort(C.begin(), C.end()); ll X = C[N / 2], sumC = accumulate(C.begin(), C.end(), 0LL); if(B + sumC < X * N) X = (B + sumC) / N; // 足りない場合 ll ans = 0; rep(i,N) ans += abs(X - C[i]); cout << ans << endl; }