C - ドラフト会議 / Draft Meeting Editorial by admin Editorial for printing
gemini-3-flash-previewOverview
In a draft meeting where \(M\) teams take turns selecting from \(N\) players, each team selects “the player with the highest evaluation value available at that point.” The problem asks for the total evaluation value of players acquired by the first team (Team Takahashi).
Analysis
The key point for solving this problem is to clarify “in what order the players are selected.”
The problem states that “all teams select the player with the highest evaluation value among the remaining players at that point.” Since all teams follow the same strategy, the order in which players are selected is simply in descending order of evaluation value \(V_i\), regardless of which team is picking.
As a concrete example, consider 5 players (evaluation values: 10, 20, 30, 40, 50) and 2 teams. 1. Sorting the evaluation values in descending order gives \([50, 40, 30, 20, 10]\). 2. The selection proceeds as follows: - 1st pick: Team 1 selects 50 - 2nd pick: Team 2 selects 40 - 3rd pick: Team 1 selects 30 - 4th pick: Team 2 selects 20 - 5th pick: Team 1 selects 10 3. Team 1 (Team Takahashi) acquires \(50 + 30 + 10 = 90\).
In this way, when evaluation values are sorted in descending order, Team Takahashi acquires the 1st, \((M+1)\)-th, \((2M+1)\)-th, … players. Thinking in terms of 0-indexed array positions, we simply need to sum the elements at positions \(0, M, 2M, \dots\).
Algorithm
- Store the evaluation values \(V\) of the \(N\) players in a list.
- Sort the list \(V\) in descending order (largest first).
- Starting from the \(0\)-th element of the sorted list, extract every \(M\)-th element and compute their sum.
- Output the computed total.
Complexity
- Time complexity: \(O(N \log N)\)
- Sorting the evaluation values takes \(O(N \log N)\). The subsequent summation is \(O(N/M)\), so sorting is the dominant factor.
- Space complexity: \(O(N)\)
- An array is needed to store the evaluation values of \(N\) players.
Implementation Notes
Sort order: The default sort is often ascending (smallest first), so you need to specify
reverse=Trueor reverse the array after sorting.Using slicing: In Python, you can easily extract every \(M\)-th element starting from index 0 using a slice like
v[0::m].Large input: Since \(N\) can be up to \(10^5\), which is relatively large, it is safer to use fast I/O (such as
sys.stdin.read).Source Code
import sys
def solve():
# 入力を取得
input_data = sys.stdin.read().split()
if not input_data:
return
n = int(input_data[0])
m = int(input_data[1])
v = list(map(int, input_data[2:]))
# 評価値を降順にソートする
# 全ての球団が最も評価値の高い選手を指名するため、
# 評価値の高い順に選手が選ばれていく
v.sort(reverse=True)
# 高橋球団(球団1)は1番目、M+1番目、2M+1番目...の選手を獲得する
# 0-indexedでは 0, M, 2M, ... 番目のインデックス
ans = sum(v[i] for i in range(0, n, m))
# 結果を出力
print(ans)
if __name__ == "__main__":
solve()
This editorial was generated by gemini-3-flash-preview.
posted:
last update: