C - ドラフト会議 / Draft Meeting 解説 by admin 印刷ページ
Claude 4.5 OpusOverview
This problem asks us to calculate the total evaluation value of players acquired by Team 1 (Takahashi’s team) in a draft meeting where \(M\) teams take turns selecting from \(N\) players.
Analysis
Key Insight
Each team follows a greedy strategy of “selecting the player with the highest evaluation value among the remaining players at that moment.”
This means that players are selected in order of decreasing evaluation value.
Understanding Through an Example
Consider the case with \(N = 5\) players and \(M = 2\) teams. If the players’ evaluation values are \([30, 50, 10, 40, 20]\), sorting in descending order gives \([50, 40, 30, 20, 10]\).
Selection process: - Round 1: Team 1 acquires \(50\), Team 2 acquires \(40\) - Round 2: Team 1 acquires \(30\), Team 2 acquires \(20\) - Round 3: Team 1 acquires \(10\) (only 1 player remains, so Team 2 doesn’t select)
Takahashi’s team (Team 1) acquires \(50 + 30 + 10 = 90\).
Discovering the Pattern
In the array sorted in descending order: - Team 1 acquires the 1st, \((M+1)\)th, \((2M+1)\)th, … players - Using 0-indexed notation, Team 1 acquires players at indices \(0, M, 2M, 3M, ...\)
In other words, Team 1 acquires players at every \(M\)-th position.
Algorithm
- Sort the players’ evaluation values in descending order
- In the sorted array, sum the evaluation values of players at indices \(0, M, 2M, 3M, ...\)
- Output the total
After sorting: V[0] ≥ V[1] ≥ V[2] ≥ ... ≥ V[N-1]
Takahashi's team acquires: V[0] + V[M] + V[2M] + ...
Complexity
Time complexity: \(O(N \log N)\)
- Sorting takes \(O(N \log N)\)
- Computing the sum takes \(O(N/M)\) (worst case \(O(N)\))
- Overall \(O(N \log N)\)
Space complexity: \(O(N)\)
- \(O(N)\) for the array storing evaluation values
Implementation Notes
Converting between 0-indexed and 1-indexed
- In the problem statement, team numbers start from 1, but using 0-indexed notation in the program makes it easier to handle
- Team 1 is index 0 in 0-indexed notation, so
range(0, N, M)correctly retrieves the desired elements
Sort direction
- Using
sort(reverse=True)sorts in descending order, placing the player with the highest evaluation value at the front
- Using
Using the range function
range(0, N, M)automatically generates \(0, M, 2M, ...\), making the loop concise
Source Code
def solve():
N, M = map(int, input().split())
V = list(map(int, input().split()))
# Sort evaluation values in descending order
V.sort(reverse=True)
# Takahashi's team is Team 1, which is index 0 in 0-indexed notation
# Selection order is 0, M, 2M, 3M, ...
# That is, after sorting, acquire players at indices 0, M, 2M, ...
total = 0
for i in range(0, N, M):
total += V[i]
print(total)
solve()
This editorial was generated by claude4.5opus.
投稿日時:
最終更新: