結果
| 問題 | 
                            No.2453 Seat Allocation
                             | 
                    
| コンテスト | |
| ユーザー | 
                             norioc
                         | 
                    
| 提出日時 | 2023-09-06 02:00:51 | 
| 言語 | PyPy3  (7.3.15)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 505 ms / 2,000 ms | 
| コード長 | 805 bytes | 
| コンパイル時間 | 167 ms | 
| コンパイル使用メモリ | 82,224 KB | 
| 実行使用メモリ | 113,504 KB | 
| 最終ジャッジ日時 | 2025-06-20 01:49:27 | 
| 合計ジャッジ時間 | 6,606 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge1 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 23 | 
ソースコード
from heapq import heappush, heappop
class Frac:
    def __init__(self, num, den, index):
        self.num = -num
        self.den = den
        self.index = index
    def __lt__(self, other):
        a = self.num * other.den
        b = other.num * self.den
        if a == b:
            return self.index < other.index
        return a < b
N, M = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
B.sort()
q = []  # (score, a-index, b-index)
for i, a in enumerate(A):
    heappush(q, (Frac(a, B[0], i), 0))
for _ in range(M):
    x, b_index = heappop(q)
    # print(f'{x.num}/{x.den} {a_index=} {b_index=}')
    print(x.index + 1)
    if b_index+1 < M:
        frac = Frac(A[x.index], B[b_index+1], x.index)
        heappush(q, (frac, b_index+1))
            
            
            
        
            
norioc