結果
問題 |
No.2770 Coupon Optimization
|
ユーザー |
|
提出日時 | 2024-12-02 21:37:37 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 833 ms / 3,000 ms |
コード長 | 1,365 bytes |
コンパイル時間 | 354 ms |
コンパイル使用メモリ | 82,304 KB |
実行使用メモリ | 181,208 KB |
最終ジャッジ日時 | 2024-12-02 21:38:30 |
合計ジャッジ時間 | 11,038 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 16 |
ソースコード
## https://yukicoder.me/problems/no/2770 from collections import deque class Queue: def __init__(self, b, size): self.b = b self.size = size self.queue = deque() self.value_sum = 0 def append(self, a): self.queue.append(a) self.value_sum += a if len(self.queue) > self.size: c = self.queue.popleft() self.value_sum -= c return c else: return None def sum(self): v = self.value_sum // 100 return v * (100 - self.b) def main(): N, M = map(int, input().split()) A = list(map(int, input().split())) B = list(map(int, input().split())) # Aを安い順番にソート A.sort() b_map = {} for b in B: if b not in b_map: b_map[b] = 0 b_map[b] += 1 b_array = [(b, count) for b, count in b_map.items()] b_array.sort(key=lambda x : x[0], reverse=True) b_queue = [Queue(b, count) for b, count in b_array] b_queue.append(Queue(0, N)) for k in range(N): a = A[k] for i in range(len(b_queue)): a = b_queue[i].append(a) if a is None: break ans = 0 for i in range(len(b_queue)): ans += b_queue[i].sum() print(ans) if __name__ == '__main__': main()