結果

問題 No.1071 ベホマラー
ユーザー FromBooskaFromBooska
提出日時 2023-08-11 10:46:37
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 192 ms / 2,000 ms
コード長 1,206 bytes
コンパイル時間 216 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 95,104 KB
最終ジャッジ日時 2024-04-29 03:15:30
合計ジャッジ時間 4,318 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
51,840 KB
testcase_01 AC 41 ms
51,840 KB
testcase_02 AC 40 ms
51,584 KB
testcase_03 AC 41 ms
51,968 KB
testcase_04 AC 41 ms
52,096 KB
testcase_05 AC 40 ms
51,968 KB
testcase_06 AC 40 ms
51,840 KB
testcase_07 AC 45 ms
56,960 KB
testcase_08 AC 44 ms
56,832 KB
testcase_09 AC 40 ms
51,840 KB
testcase_10 AC 126 ms
89,856 KB
testcase_11 AC 122 ms
87,296 KB
testcase_12 AC 88 ms
79,488 KB
testcase_13 AC 136 ms
85,120 KB
testcase_14 AC 112 ms
90,624 KB
testcase_15 AC 124 ms
94,592 KB
testcase_16 AC 124 ms
94,464 KB
testcase_17 AC 154 ms
94,464 KB
testcase_18 AC 127 ms
93,824 KB
testcase_19 AC 192 ms
95,104 KB
testcase_20 AC 109 ms
92,416 KB
testcase_21 AC 111 ms
93,952 KB
testcase_22 AC 107 ms
92,800 KB
testcase_23 AC 112 ms
93,184 KB
testcase_24 AC 131 ms
94,516 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# 二分探索でやってみる
# 非線形なので三分探索にする

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

AK = []
for a in A:
    calc = (a-1+K-1)//K
    AK.append(calc)
    
#print(AK)

if sum(AK) == 0:
    print(0)
    exit()

def check(y):
    x = 0
    for ak in AK:
        x += max(0, ak-y)
    magic = x*X+y*Y
    return magic
    
#for y in range(0, max(AK)+1):
#    print(y, check(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, max(AK)+1
while right-left > 2:
    left_mid, right_mid = (2*left+right)//3, (left+2*right)//3
    if check(left_mid) <= check(right_mid):
        # 右midの方が大きいから右を右midに変える
        right = right_mid
    else:
        left = left_mid

ans = min(check(left_mid), check(right_mid))
# leftとrightの間も入れる必要あるのか? ない
print(ans)







0