結果

問題 No.2860 Heal Slimes
ユーザー rin204
提出日時 2024-08-25 16:24:20
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 965 bytes
コンパイル時間 239 ms
コンパイル使用メモリ 82,560 KB
実行使用メモリ 107,384 KB
最終ジャッジ日時 2024-08-25 16:24:31
合計ジャッジ時間 10,458 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 54 WA * 6
権限があれば一括ダウンロードができます

ソースコード

diff #

def solve():
    n, k, x = map(int, input().split())
    H = list(map(int, input().split()))
    if len(set(h % x for h in H)) != 1:
        print("No")
        return

    tot = [0] * k
    H = [h // x for h in H]
    ma = max(H)

    for i, h in enumerate(H):
        tot[i % k] += ma - h

    bef = tot[: n % k]
    aft = tot[n % k :]
    if bef and len(set(bef)) >= 2:
        print("No")
        return
    if aft and len(set(aft)) >= 2:
        print("No")
        return

    if bef and aft:
        if bef[0] > aft[0]:
            print("No")
            return

        d = aft[0] - bef[0]
        goal = ma + d
        rem = [goal - h for h in H]
        minus = [0] * (n + k)
        x = 0
        for i, r in enumerate(rem):
            x -= minus[i]
            r -= x
            if r < 0:
                print("No")
                return
            minus[i + k] = r
            x += r

    print("Yes")


for _ in range(int(input())):
    solve()
0