結果
| 問題 |
No.198 キャンディー・ボックス2
|
| コンテスト | |
| ユーザー |
kyuridenamida
|
| 提出日時 | 2015-04-28 23:48:16 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 776 bytes |
| コンパイル時間 | 1,149 ms |
| コンパイル使用メモリ | 162,556 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-07-05 05:09:15 |
| 合計ジャッジ時間 | 1,933 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 21 WA * 5 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
long long f(vector<long long> A,long long x){
long long cnt = 0;
for(int i = 0 ; i < A.size() ; i++) cnt += abs(A[i]-x);
return cnt;
}
int main(){
long long B,N;
cin >> B >> N;
vector<long long> C(N);
long long sum = B;
for(int i = 0 ; i < N ; i++){
cin >> C[i];
sum += C[i];
}
sum /= N;
vector<long long> cand;
for(int i = 1 ; i < (1<<N) ; i++){
long long s = 0;
for(int j = 0 ; j < N ; j++){
if( i >> j & 1 ) s += C[j];
}
s /= __builtin_popcount(i);
for(int k = -2 ; k <= 2 ; k++){
long long t = s + k;
if( t >= 0 ) cand.push_back(t);
}
}
long long ans = 1e15;
for( auto x : cand ){
ans = min(f(C,x),ans);
//cout << x << ": " << f(C,x) << endl;
}
cout << ans << endl;
}
kyuridenamida