結果
| 問題 |
No.2453 Seat Allocation
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-09-05 14:53:22 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,461 bytes |
| コンパイル時間 | 523 ms |
| コンパイル使用メモリ | 82,176 KB |
| 実行使用メモリ | 108,772 KB |
| 最終ジャッジ日時 | 2024-06-23 10:30:53 |
| 合計ジャッジ時間 | 11,431 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 21 WA * 1 |
ソースコード
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())) + [1]
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]))