結果

問題 No.2453 Seat Allocation
ユーザー noriocnorioc
提出日時 2023-09-06 01:57:59
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,522 ms / 2,000 ms
コード長 863 bytes
コンパイル時間 309 ms
コンパイル使用メモリ 87,324 KB
実行使用メモリ 132,372 KB
最終ジャッジ日時 2023-09-07 15:39:13
合計ジャッジ時間 15,193 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,320 KB
testcase_01 AC 73 ms
71,288 KB
testcase_02 AC 73 ms
71,284 KB
testcase_03 AC 75 ms
71,396 KB
testcase_04 AC 75 ms
71,640 KB
testcase_05 AC 943 ms
129,876 KB
testcase_06 AC 305 ms
91,884 KB
testcase_07 AC 319 ms
98,760 KB
testcase_08 AC 216 ms
80,784 KB
testcase_09 AC 1,522 ms
132,064 KB
testcase_10 AC 1,483 ms
132,372 KB
testcase_11 AC 1,430 ms
132,328 KB
testcase_12 AC 294 ms
91,100 KB
testcase_13 AC 456 ms
91,920 KB
testcase_14 AC 178 ms
91,176 KB
testcase_15 AC 628 ms
95,772 KB
testcase_16 AC 437 ms
90,956 KB
testcase_17 AC 75 ms
71,596 KB
testcase_18 AC 1,101 ms
117,128 KB
testcase_19 AC 1,191 ms
125,932 KB
testcase_20 AC 542 ms
94,596 KB
testcase_21 AC 699 ms
97,876 KB
testcase_22 AC 993 ms
113,588 KB
testcase_23 AC 74 ms
71,480 KB
testcase_24 AC 75 ms
71,284 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), 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], a_index)
        heappush(q, (frac, a_index, b_index+1))

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