結果

問題 No.1297 銅像
ユーザー lam6er
提出日時 2025-04-16 16:16:57
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,106 bytes
コンパイル時間 160 ms
コンパイル使用メモリ 82,464 KB
実行使用メモリ 121,568 KB
最終ジャッジ日時 2025-04-16 16:18:38
合計ジャッジ時間 11,773 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 6 WA * 15
権限があれば一括ダウンロードができます

ソースコード

diff #

def main():
    import sys
    input = sys.stdin.read().split()
    idx = 0
    N, C = int(input[idx]), int(input[idx+1])
    idx += 2
    a = []
    b = []
    for _ in range(N):
        ai = int(input[idx])
        bi = int(input[idx+1])
        a.append(ai)
        b.append(bi)
        idx += 2
    
    used = [False] * (N + 1)  # 1-based indexing
    total = 0
    K = 200  # Adjust this value based on problem constraints
    
    for j in range(1, N + 1):
        min_cost = float('inf')
        best_i = -1
        start = max(1, j - K)
        end = min(N, j + K)
        for i in range(start, end + 1):
            current_a = a[i - 1]
            current_b = b[i - 1]
            travel_cost = C * abs(i - j)
            if not used[i]:
                cost = current_b + current_a + travel_cost
            else:
                cost = current_a + travel_cost
            if cost < min_cost:
                min_cost = cost
                best_i = i
        total += min_cost
        if not used[best_i]:
            used[best_i] = True
    print(total)

if __name__ == '__main__':
    main()
0