結果

問題 No.198 キャンディー・ボックス2
ユーザー k
提出日時 2020-07-22 19:30:01
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 675 bytes
コンパイル時間 2,032 ms
コンパイル使用メモリ 194,180 KB
最終ジャッジ日時 2025-01-12 01:59:41
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 22 WA * 4
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for (int i=(int)(b); i<(int)(e); i++)
#define ALL(x) (x).begin(), (x).end()

const double PI = acos(-1);

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  
  long long b; cin >> b;
  int n; cin >> n;
  vector<long long> c(n);
  REP (i, n) cin >> c[i];

  long long sum = 0;
  REP (i, n) sum += c[i];
  
  long long ret = 1LL<<60;
  REP (i, n) {
    if (sum + b < n * c[i])
      continue;
    
    long long tmp = 0;
    REP (j, n) {
      tmp += abs(c[j] - c[i]);
    }
    ret = min(ret, tmp);    
  }
  
  cout << ret << endl;
    
  return 0;
}
0