結果
| 問題 | No.433 ICPC国内予選の選抜ルールがこんな感じだったらうれしい |
| コンテスト | |
| ユーザー |
lam6er
|
| 提出日時 | 2025-04-15 23:27:13 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 561 ms / 4,000 ms |
| コード長 | 1,502 bytes |
| コンパイル時間 | 212 ms |
| コンパイル使用メモリ | 82,836 KB |
| 実行使用メモリ | 134,044 KB |
| 最終ジャッジ日時 | 2025-04-15 23:28:48 |
| 合計ジャッジ時間 | 15,222 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 48 |
ソースコード
import heapq
from collections import defaultdict
def main():
import sys
input = sys.stdin.read
data = input().split()
idx = 0
n = int(data[idx])
k = int(data[idx+1])
idx += 2
teams = []
for original_idx in range(n):
s = int(data[idx])
p = int(data[idx+1])
u = int(data[idx+2])
teams.append((s, p, u, original_idx))
idx += 3
groups = defaultdict(list)
for s, p, u, original_idx in teams:
groups[u].append((s, p, original_idx))
# Sort each group's teams by descending S, then ascending P
for u in groups:
groups[u].sort(key=lambda x: (-x[0], x[1]))
heap = []
for u in groups:
if groups[u]:
s, p, original_idx = groups[u][0]
heapq.heappush(heap, (-s, 0, p, u, 0))
selected_teams_count = defaultdict(int)
selected = []
for _ in range(k):
s_neg, count, p, u, index = heapq.heappop(heap)
s = -s_neg
team = groups[u][index]
original_idx = team[2]
selected.append(original_idx)
selected_teams_count[u] += 1
next_index = selected_teams_count[u]
if next_index < len(groups[u]):
next_team = groups[u][next_index]
next_s, next_p, next_original_idx = next_team
heapq.heappush(heap, (-next_s, next_index, next_p, u, next_index))
for idx in selected:
print(idx)
if __name__ == "__main__":
main()
lam6er