結果

問題 No.1071 ベホマラー
ユーザー yassu0320yassu0320
提出日時 2022-02-08 21:08:36
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 296 ms / 2,000 ms
コード長 1,892 bytes
コンパイル時間 253 ms
コンパイル使用メモリ 87,108 KB
実行使用メモリ 100,456 KB
最終ジャッジ日時 2023-09-05 21:33:02
合計ジャッジ時間 8,006 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 180 ms
78,608 KB
testcase_01 AC 179 ms
78,576 KB
testcase_02 AC 183 ms
78,504 KB
testcase_03 AC 184 ms
78,156 KB
testcase_04 AC 186 ms
78,660 KB
testcase_05 AC 179 ms
78,716 KB
testcase_06 AC 180 ms
78,440 KB
testcase_07 AC 176 ms
78,604 KB
testcase_08 AC 175 ms
78,580 KB
testcase_09 AC 173 ms
78,576 KB
testcase_10 AC 296 ms
96,972 KB
testcase_11 AC 245 ms
95,792 KB
testcase_12 AC 229 ms
90,316 KB
testcase_13 AC 228 ms
93,196 KB
testcase_14 AC 246 ms
97,932 KB
testcase_15 AC 256 ms
100,456 KB
testcase_16 AC 258 ms
100,456 KB
testcase_17 AC 247 ms
98,980 KB
testcase_18 AC 242 ms
99,176 KB
testcase_19 AC 240 ms
99,384 KB
testcase_20 AC 216 ms
98,992 KB
testcase_21 AC 215 ms
98,916 KB
testcase_22 AC 215 ms
98,900 KB
testcase_23 AC 217 ms
98,648 KB
testcase_24 AC 234 ms
99,468 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env pypy3

from pprint import pprint
from string import ascii_lowercase as letter
from sys import setrecursionlimit, stdin
from typing import Dict, Iterable, Set

INF: int = 1 << 62
MOD1000000007 = 10**9 + 7
MOD998244353 = 998244353
setrecursionlimit(500_000)
readline = stdin.readline
input = lambda: stdin.readline().rstrip('\r\n')


def inputs(type_=int):
    ins = input().split()

    if isinstance(type_, Iterable):
        return [t(x) for t, x in zip(type_, ins)]
    else:
        return list(map(type_, ins))


def input_(type_=int):
    a, = inputs(type_)
    return a


def input1() -> int:
    return int(readline())


inputi = input1


def input2():
    a = readline().split()
    assert len(a) == 2
    a[0] = int(a[0])
    a[1] = int(a[1])
    return a


def input3():
    a = readline().split()
    assert len(a) == 3
    a[0] = int(a[0])
    a[1] = int(a[1])
    a[2] = int(a[2])
    return a


def input4():
    a = readline().split()
    assert len(a) == 4
    a[0] = int(a[0])
    a[1] = int(a[1])
    a[2] = int(a[2])
    a[3] = int(a[3])
    return a


# start coding
def ceil(b, a):
    return (a + b - 1) // a


n, k, x, y = input4()
A = inputs()
A = [a - 1 for a in A]
A.sort()
A = [0] + A + [INF]
n += 1
B = [0] * n
for i in range(1, n):
    B[i] = B[i - 1] + ceil(A[i], k)

res = INF
for i in range(n):
    b = ceil(A[i], k)
    val = b * y
    # print(83, i, val)

    # TODO: 値がb * kより大きい最小のindexを求めてrとする.
    left = 0
    right = n
    while right - left > 1:
        mid = (left + right) // 2
        if A[mid] <= b * k:
            left = mid
        else:
            right = mid
    r = right

    if r != n:
        # r ... n-1までの値を足す
        c = B[n - 1] - B[r - 1] - b * (n - r)
        # print(99, i, c, y)
        val += c * x

    # print(i, A, b, r, val)
    res = min(res, val)

print(res)
0