結果

問題 No.2453 Seat Allocation
ユーザー noriocnorioc
提出日時 2023-09-06 02:00:51
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 552 ms / 2,000 ms
コード長 805 bytes
コンパイル時間 466 ms
コンパイル使用メモリ 86,784 KB
実行使用メモリ 112,648 KB
最終ジャッジ日時 2023-09-07 15:39:15
合計ジャッジ時間 8,373 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
71,284 KB
testcase_01 AC 75 ms
71,372 KB
testcase_02 AC 77 ms
71,284 KB
testcase_03 AC 75 ms
71,340 KB
testcase_04 AC 75 ms
71,172 KB
testcase_05 AC 336 ms
112,648 KB
testcase_06 AC 177 ms
90,880 KB
testcase_07 AC 180 ms
97,700 KB
testcase_08 AC 159 ms
79,924 KB
testcase_09 AC 547 ms
111,268 KB
testcase_10 AC 520 ms
111,840 KB
testcase_11 AC 552 ms
109,704 KB
testcase_12 AC 259 ms
90,640 KB
testcase_13 AC 285 ms
91,696 KB
testcase_14 AC 151 ms
90,660 KB
testcase_15 AC 328 ms
91,188 KB
testcase_16 AC 325 ms
90,920 KB
testcase_17 AC 76 ms
71,156 KB
testcase_18 AC 403 ms
101,848 KB
testcase_19 AC 468 ms
107,792 KB
testcase_20 AC 262 ms
87,468 KB
testcase_21 AC 258 ms
86,744 KB
testcase_22 AC 368 ms
97,896 KB
testcase_23 AC 75 ms
71,372 KB
testcase_24 AC 75 ms
71,152 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))

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