結果

問題 No.198 キャンディー・ボックス2
ユーザー prtoq3prtoq3
提出日時 2018-10-28 19:31:28
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 743 bytes
コンパイル時間 2,215 ms
コンパイル使用メモリ 198,420 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-08-12 08:08:43
合計ジャッジ時間 3,582 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 WA -
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 WA -
testcase_20 AC 1 ms
4,380 KB
testcase_21 WA -
testcase_22 AC 2 ms
4,380 KB
testcase_23 WA -
testcase_24 AC 2 ms
4,376 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 1 ms
4,380 KB
testcase_28 WA -
testcase_29 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘ll func(int)’ 内:
main.cpp:21:28: 警告: 左シフト回数 >= 型の幅となっています [-Wshift-count-overflow]
   21 |     if (stock < 0) return 1<<60;
      |                           ~^~~~

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
const int INF = 1000000000;

#define REP(i,n) for((i)=0;(i)<(int)(n);(i)++)

int n, b;
int a[20];

ll func(int x){
    ll ret = 0;
    ll stock = b;
    for (int i = 0; i < n; i++){
        if (a[i] < x) stock -= (x - a[i]);
        else stock += (a[i] - x);
        ret += abs(a[i] - x);
    }

    if (stock < 0) return 1<<60;
    return ret;
}

int main(){
    cin >> b >> n;
    for (int i = 0; i < n; i++) cin >> a[i];

    int ng = -1;
    int ok = INF;
    while(abs(ok - ng) > 1){
        int mid = (ok + ng) / 2;
        if (func(mid) <= func(mid + 1)) ok = mid;
        else ng = mid;
    }

    cout << func(ok) << endl;

    return 0;
}
0