結果

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
  long long x;cin>>x;
  int n;cin>>n;
  vector<long long> A(n);
  long long sm = x;
  for(int i = 0; n > i; i++){
    cin>>A[i];sm += A[i];
  }
  long long ans = 1000000000000;
  for(int i = 0; n > i; i++){
    if(n*A[i] > sm)continue;
    long long tmp = 0;
    for(int j = 0; n > j; j++){
      tmp += abs(A[i]-A[j]);
    }
    ans = min(ans,tmp);
  }
  cout << ans << endl;
}
0