結果

問題 No.1071 ベホマラー
ユーザー FromBooskaFromBooska
提出日時 2023-03-12 10:59:49
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,124 bytes
コンパイル時間 1,278 ms
コンパイル使用メモリ 81,468 KB
実行使用メモリ 87,372 KB
最終ジャッジ日時 2023-10-18 10:31:44
合計ジャッジ時間 4,669 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 WA -
testcase_10 WA -
testcase_11 AC 117 ms
81,388 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 141 ms
87,032 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# ベホマラーの回数をbとすれば、ベホイミの総回数aは決まる
# よってa*X+b*Yも決まる
# しかしこの関数は凹形だろう、二分探索ではなく三分探索でできるか

N, K, X, Y = map(int, input().split())
A = list(map(int, input().split()))

def calc_total(b):
    a = 0
    for i in range(N):
        a += max(0, (A[i]-1-b*K+(K-1))//K)
    return a*X+b*Y

# 谷、つまり1極値を求める三分探索での解き方
# https://roiti46.hatenablog.com/entry/2015/04/29/yukicoder_No.198_%E3%82%AD%E3%83%A3%E3%83%B3%E3%83%87%E3%82%A3%E3%83%BC%E3%83%BB%E3%83%9C%E3%83%83%E3%82%AF%E3%82%B9%EF%BC%92
# https://qiita.com/ganyariya/items/1553ff2bf8d6d7789127

left, right = -1, 10**18
while right-left > 2:
    left_mid, right_mid = (2*left+right)//3, (left+2*right)//3
    if calc_total(left_mid) <= calc_total(right_mid):
        # 右midの方が大きいから右を右midに変える
        right = right_mid
    else:
        left = left_mid

#print(left, right)

ans = min(calc_total(left), calc_total(right))
# leftとrightの間も入れる必要あるのか?
print(ans)



0