結果

問題 No.2453 Seat Allocation
コンテスト
ユーザー norioc
提出日時 2023-09-06 01:55:52
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 1,161 ms / 2,000 ms
コード長 872 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 119 ms
コンパイル使用メモリ 85,284 KB
実行使用メモリ 131,660 KB
最終ジャッジ日時 2026-03-09 04:41:37
合計ジャッジ時間 10,639 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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