結果

問題 No.2453 Seat Allocation
ユーザー noriocnorioc
提出日時 2023-09-06 02:01:37
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 538 ms / 2,000 ms
コード長 842 bytes
コンパイル時間 380 ms
コンパイル使用メモリ 87,268 KB
実行使用メモリ 118,700 KB
最終ジャッジ日時 2023-09-07 15:39:14
合計ジャッジ時間 7,950 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
71,036 KB
testcase_01 AC 75 ms
71,292 KB
testcase_02 AC 74 ms
71,468 KB
testcase_03 AC 75 ms
71,208 KB
testcase_04 AC 76 ms
71,572 KB
testcase_05 AC 339 ms
117,992 KB
testcase_06 AC 171 ms
91,612 KB
testcase_07 AC 176 ms
97,480 KB
testcase_08 AC 158 ms
80,844 KB
testcase_09 AC 538 ms
118,284 KB
testcase_10 AC 520 ms
118,700 KB
testcase_11 AC 529 ms
118,112 KB
testcase_12 AC 241 ms
91,336 KB
testcase_13 AC 248 ms
91,984 KB
testcase_14 AC 145 ms
91,344 KB
testcase_15 AC 304 ms
91,532 KB
testcase_16 AC 302 ms
91,108 KB
testcase_17 AC 76 ms
71,328 KB
testcase_18 AC 394 ms
108,484 KB
testcase_19 AC 448 ms
114,296 KB
testcase_20 AC 253 ms
90,308 KB
testcase_21 AC 252 ms
91,704 KB
testcase_22 AC 357 ms
105,232 KB
testcase_23 AC 75 ms
71,336 KB
testcase_24 AC 75 ms
71,372 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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))

ans = []
for _ in range(M):
    x, b_index = heappop(q)
    # print(f'{x.num}/{x.den} {a_index=} {b_index=}')
    ans.append(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))

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