結果

問題 No.2453 Seat Allocation
ユーザー norioc
提出日時 2023-09-06 01:55:52
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 872 bytes
コンパイル時間 226 ms
コンパイル使用メモリ 82,580 KB
実行使用メモリ 134,280 KB
最終ジャッジ日時 2024-06-23 20:59:02
合計ジャッジ時間 18,985 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21 TLE * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heappush, heappop


class Frac:
    def __init__(self, num, den):
        self.num = -num
        self.den = den

    def __eq__(self, other):
        a = self.num * other.den
        b = other.num * self.den
        return a == b

    def __lt__(self, other):
        a = self.num * other.den
        b = other.num * self.den
        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))

ans = []
for _ in range(M):
    x, a_index, b_index = heappop(q)
    # print(f'{x.num}/{x.den} {a_index=} {b_index=}')
    ans.append(a_index + 1)
    if b_index+1 < M:
        frac = Frac(A[a_index], B[b_index+1])
        heappush(q, (frac, a_index, b_index+1))

print(*ans, sep='\n')
0