結果

問題 No.2453 Seat Allocation
ユーザー fiblonaria
提出日時 2023-09-05 14:51:31
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 1,455 bytes
コンパイル時間 256 ms
コンパイル使用メモリ 82,572 KB
実行使用メモリ 108,772 KB
最終ジャッジ日時 2024-06-23 10:29:02
合計ジャッジ時間 12,466 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 19 RE * 3
権限があれば一括ダウンロードができます

ソースコード

diff #

class heap:
    #comp:比較関数 小さいものから順に取り出す
    def __init__(s, comp = lambda x:x):
        s.comp = comp
        s.values = []
    #index と 子供たちの位置関係を調整
    def adjust(s, index):
        next = None
        cur = s.comp(s.values[index])
        for i in range(index * 2 + 1, min(index * 2 + 3, len(s.values))):
            if cur > s.comp(s.values[i]):
                next = i
                cur = s.comp(s.values[i])
        if next != None:
            s.values[index], s.values[next] = s.values[next], s.values[index]
            return next
        else:
            return None
    def push(s, value):
        s.values.append(value)
        index = (len(s.values) - 2) // 2
        while index >= 0:
            s.adjust(index)
            index = (index - 1) // 2
    def pop(s):
        if len(s.values) == 0:
            return None
        if len(s.values) == 1:
            return s.values.pop()
        ret = s.values[0]
        s.values[0] = s.values.pop()
        index = 0
        while index != None:
            index = s.adjust(index)
        return ret
N, M = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
number = [0 for i in range(N)]
H = heap()
for i in range(N):
	H.push((-(A[i] / B[0]), i))
for i in range(M):
	cur = H.pop()
	number[cur[1]] += 1
	print(cur[1] + 1)
	H.push((-(A[cur[1]] / B[number[cur[1]]]), cur[1]))
0