結果
問題 |
No.1297 銅像
|
ユーザー |
![]() |
提出日時 | 2025-04-15 23:19:40 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,106 bytes |
コンパイル時間 | 239 ms |
コンパイル使用メモリ | 81,456 KB |
実行使用メモリ | 120,932 KB |
最終ジャッジ日時 | 2025-04-15 23:21:09 |
合計ジャッジ時間 | 11,913 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 6 WA * 15 |
ソースコード
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()