結果

問題 No.198 キャンディー・ボックス2
ユーザー alpha_virginisalpha_virginis
提出日時 2016-12-27 16:10:38
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,263 bytes
コンパイル時間 1,383 ms
コンパイル使用メモリ 165,228 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-08-21 14:50:57
合計ジャッジ時間 3,851 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 WA -
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 2 ms
4,504 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#ifndef LOCAL_
#define fprintf if( false ) fprintf
#endif // LOCAL_
#define dumpi(x1) fprintf(stderr, "#%s.%d (%s) = (%d)\n", __func__, __LINE__, #x1, x1);
#define dumpii(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%d, %d)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define dumpiii(x1, x2, x3) fprintf(stderr, "#%s.%d (%s, %s, %s) = (%d, %d, %d)\n", __func__, __LINE__, #x1, #x2, #x3, x1, x2, x3);
#define dumpl(x1) fprintf(stderr, "#%s.%d (%s) = (%ld)\n", __func__, __LINE__, #x1, x1);
#define dumpd(x1) fprintf(stderr, "#%s.%d (%s) = (%lf)\n", __func__, __LINE__, #x1, x1);

int b;
int n;
int xs[16];
int total;
int max;

long calc(long t) {
  long res = 0;
  for(int i = 0; i < n; ++i) {
    res += std::abs(t - xs[i]);
  }
  return t * n <= total and t <= max ? res : -1;
}

void init() {
  total += b;
  for(int i = 0; i < n; ++i) {
    total += xs[i];
    max = std::max(max, xs[i]);
  }
}

int main() {
  scanf("%d", &b);
  scanf("%d", &n);
  for(int i = 0; i < (int)n; ++i) {
    scanf("%d", &xs[i]);
  }
  init();
  long x = 0;
  for(int i = 30; i >= 0; --i) {
    long shift = (1LL << i);
    if( calc(x + shift) >= 0 ) {
      x = x + shift;
    }
  }
  dumpii((int)x, (int)calc(x));
  printf("%ld\n", calc(x));
  return 0;
}
0