結果
| 問題 | No.198 キャンディー・ボックス2 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-10-10 00:30:47 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 1,000 ms |
| コード長 | 491 bytes |
| コンパイル時間 | 1,692 ms |
| コンパイル使用メモリ | 201,060 KB |
| 実行使用メモリ | 7,720 KB |
| 最終ジャッジ日時 | 2025-11-26 11:47:05 |
| 合計ジャッジ時間 | 2,791 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 27 |
ソースコード
#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;
}