結果
問題 | No.198 キャンディー・ボックス2 |
ユーザー |
![]() |
提出日時 | 2016-12-27 16:10:38 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,263 bytes |
コンパイル時間 | 1,512 ms |
コンパイル使用メモリ | 167,360 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-12-15 03:29:54 |
合計ジャッジ時間 | 2,522 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 9 WA * 17 |
ソースコード
#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; }