公式

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

GPT 5.2 High

Overview

This problem asks us to find the total evaluation value of players acquired by Takahashi’s team (Team 1) when each team takes turns picking “the player with the highest evaluation value among the remaining players.”

Analysis

The key observation is that since “everyone always picks the highest-rated player,” the drafting process simply consumes players from the front of the list when sorted in descending order of evaluation value.

  • First, if we sort all players in descending order of evaluation value, the overall draft order matches this sorted order.
    Reason: At any point, the “maximum value among the remaining” is chosen, so the 1st pick is the overall maximum, the 2nd pick is the second largest, and so on.
  • The picking order repeats as Team 1 → 2 → … → M → 1 → …, so from the array sorted in descending order, the elements at positions:
    • 1st (index 0)
    • \((M+1)\)th (index \(M\))
    • \((2M+1)\)th (index \(2M\))
    • …

are the players acquired by Takahashi’s team.

For example, with \(N=7, M=3\), sorting evaluation values in descending order gives:
\([100, 90, 80, 70, 60, 50, 40]\)
The picks are: Round 1: Team 1 gets 100, Team 2 gets 90, Team 3 gets 80
Round 2: Team 1 gets 70, Team 2 gets 60, Team 3 gets 50
Round 3: Team 1 gets 40
Thus, Takahashi’s team takes the “0th, 3rd, and 6th elements,” and the total is \(100+70+40=210\).

A naive simulation of “finding the maximum each time” would take \(O(N)\) per search, resulting in \(O(N^2)\) overall, which is too slow for \(N \le 10^5\).
Instead, we speed this up by “sorting in descending order first and summing only the necessary positions.”

Algorithm

  1. Sort the evaluation value array \(V\) in descending order.
  2. Takahashi’s team picks \(V[0], V[M], V[2M], \ldots\), so sum these values.
    • In Python, you can extract them using a slice with a step like V[0:N:M].
  3. Output the sum.

Complexity

  • Time complexity: Dominated by sorting, so \(O(N \log N)\)
  • Space complexity: \(O(N)\) for storing the array

Implementation Notes

  • You can write it concisely by using V.sort(reverse=True) for descending sort, then sum(V[0:N:M]).

  • The total can be as large as \(10^9 \times 10^5 = 10^{14}\), but since Python’s int has arbitrary precision, this is not an issue.

    Source Code

import sys

def main():
    input = sys.stdin.readline
    N, M = map(int, input().split())
    V = list(map(int, input().split()))
    V.sort(reverse=True)
    ans = sum(V[0:N:M])
    print(ans)

if __name__ == "__main__":
    main()

This editorial was generated by gpt-5.2-high.

投稿日時:
最終更新: