結果
問題 |
No.2549 Paint Eggs
|
ユーザー |
![]() |
提出日時 | 2023-11-19 21:41:12 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,626 ms / 2,000 ms |
コード長 | 619 bytes |
コンパイル時間 | 541 ms |
コンパイル使用メモリ | 82,176 KB |
実行使用メモリ | 156,184 KB |
最終ジャッジ日時 | 2024-09-26 06:25:40 |
合計ジャッジ時間 | 31,671 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 45 |
ソースコード
import heapq n, m, k = map(int, input().split()) c = list(map(lambda x: int(x)-1, input().split())) a = list(map(int, input().split())) d = dict() for i in range(m): d[i] = a[i] * k for i in range(k): d[c[i]] -= a[c[i]] ans = min(d.values()) # print(d) h = [] for i in d.keys(): heapq.heappush(h, m*d[i]+i) for i in range(n-k): d[c[i]] += a[c[i]] d[c[i+k]] -= a[c[i+k]] heapq.heappush(h, m*d[c[i]]+c[i]) heapq.heappush(h, m*d[c[i+k]]+c[i+k]) while h: cost, idx = divmod(heapq.heappop(h), m) if d[idx] == cost: ans = min(ans, cost) heapq.heappush(h, m*cost+idx) break print(ans)