公式

C - ドラフト会議 / Draft Meeting 解説 by admin 印刷ページ

Qwen3-Coder-480B

Overview

In a professional baseball draft, each team sequentially acquires the player with the highest evaluation value. Find the total evaluation value of the players acquired by Takahashi’s team (Team 1).

Analysis

In this problem, each team greedily selects “the player with the highest evaluation value among the remaining players.” Therefore, if we sort all players in descending order of evaluation value, the selection order becomes clear.

For example, suppose the players are arranged by evaluation value as \([9, 7, 5, 3, 1]\). Since teams pick in order of their team number, players are acquired as follows:

  • Round 1: Team 1 gets 9, Team 2 gets 7, Team 3 gets 5
  • Round 2: Team 1 gets 3, Team 2 gets 1

In other words, Takahashi’s team (Team 1) acquires the players at indices \(0, M, 2M, \ldots\) in the sorted list.

Since the answer can be obtained by simply sorting the players and then selecting at regular intervals, there is no need to perform a simulation, and the problem can be solved efficiently.

A naive approach of finding and removing the maximum value among the remaining players each time (e.g., using a priority queue with deletions) could lead to worse time complexity and potentially result in TLE. However, since we only need to pick indices at regular intervals from a sorted array, the processing is very fast.

Algorithm

  1. Sort the input list of player evaluation values \(V\) in descending order.
  2. From the sorted list, extract the elements at the indices that Takahashi’s team picks (\(0, M, 2M, \ldots\)) and sum them up.
  3. Output the total sum.

Complexity

  • Time complexity: \(O(N \log N)\) (dominated by sorting)
  • Space complexity: \(O(1)\) (no additional space beyond the input is used)

Implementation Notes

  • The evaluation values must be sorted in descending order.

  • Takahashi’s team picks the players at positions with indices \(0, M, 2M, \ldots\) in the sorted list.

  • In Python, range(0, N, M) can be used to easily iterate over these indices.

    Source Code

import heapq

def main():
    import sys
    input = sys.stdin.read
    data = input().split()
    
    N = int(data[0])
    M = int(data[1])
    V = list(map(int, data[2:]))

    # 評価値を降順にソート
    V.sort(reverse=True)
    
    # 高橋球団(球団1)が獲得する選手のインデックスは
    # 0, M, 2M, 3M, ...
    total = 0
    for i in range(0, N, M):
        total += V[i]
    
    print(total)

if __name__ == "__main__":
    main()

This editorial was generated by qwen3-coder-480b.

投稿日時:
最終更新: