結果

問題 No.2627 Unnatural Pitch
ユーザー 👑 rin204rin204
提出日時 2024-02-10 00:25:38
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 250 ms / 4,000 ms
コード長 773 bytes
コンパイル時間 312 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 133,368 KB
最終ジャッジ日時 2024-02-10 00:25:44
合計ジャッジ時間 5,275 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,460 KB
testcase_01 AC 34 ms
53,460 KB
testcase_02 AC 38 ms
53,460 KB
testcase_03 AC 34 ms
53,460 KB
testcase_04 AC 157 ms
100,132 KB
testcase_05 AC 158 ms
100,132 KB
testcase_06 AC 148 ms
106,936 KB
testcase_07 AC 131 ms
106,936 KB
testcase_08 AC 146 ms
107,512 KB
testcase_09 AC 192 ms
133,348 KB
testcase_10 AC 187 ms
133,368 KB
testcase_11 AC 53 ms
66,548 KB
testcase_12 AC 57 ms
66,544 KB
testcase_13 AC 39 ms
59,624 KB
testcase_14 AC 53 ms
66,548 KB
testcase_15 AC 45 ms
64,476 KB
testcase_16 AC 243 ms
103,968 KB
testcase_17 AC 250 ms
111,392 KB
testcase_18 AC 235 ms
101,536 KB
testcase_19 AC 233 ms
108,960 KB
testcase_20 AC 126 ms
86,540 KB
testcase_21 AC 157 ms
88,432 KB
testcase_22 AC 206 ms
98,928 KB
testcase_23 AC 141 ms
88,072 KB
testcase_24 AC 163 ms
93,512 KB
testcase_25 AC 169 ms
93,980 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n, k, L, U = map(int, input().split())
A = list(map(int, input().split()))
l = -(1 << 60)
r = 1 << 60
while r - l > 1:
    mid = (l + r) // 2
    c = 0
    for a in A:
        x = a + mid
        if x < L:
            c += 1
        elif x + k >= U:
            c -= 1
    if c > 0:
        l = mid
    else:
        r = mid

A = [a + r for a in A]
tot = 0
add = {}
for a in A:
    if a < L:
        tot += (L - a + k - 1) // k
        x = (L - a) % k
        if x == 0:
            x = k
        add[x] = add.get(x, 0) - 1
    elif a + k > U:
        tot += (a - U + k - 1) // k
        x = (U - a + 1) % k
        if x == 0:
            x = k
        add[x] = add.get(x, 0) + 1

ans = tot
for k in sorted(add.keys()):
    tot += add[k]
    ans = min(ans, tot)
print(ans)
0