B - チーム編成 / Team Formation Editorial by admin
Qwen3-Coder-480BOverview
We always include Aoki in the team, then select the remaining members in descending order of skill value, and compute the total skill value of the entire team.
Analysis
In this problem, we must always include Aoki (player \(T\)) in the team.
After that, we select the remaining \(K - 1\) members from “players other than Aoki” in descending order of skill value.
A straightforward approach would be to sort everyone’s skill values and select the top \(K\) players,
but this doesn’t guarantee that Aoki will be selected, so we need to be more careful.
Therefore, we consider the following procedure:
- Save Aoki’s skill value separately
- Remove Aoki from the candidate list
- Sort the remaining candidates in descending order of skill value
- Add Aoki’s skill value to the sum of the top \(K - 1\) players’ skill values
This ensures that Aoki is definitely included in the team while also optimally selecting the other members.
Algorithm
- Read the input and create the list of players’ skill values \(A\)
- Retrieve Aoki’s skill value (at index \(T - 1\)) and remove it from list \(A\)
- Sort list \(A\) in descending order
- Compute the sum of the first \(K - 1\) elements of the sorted list and add Aoki’s skill value to it
- Output the total
Complexity
- Time complexity: \(O(N \log N)\) (dominated by sorting)
- Space complexity: \(O(N)\) (storing the skill value list)
Implementation Notes
- Aoki’s index is given as 1-based, not 0-based, so use
T - 1when accessing the list pop()can be used to remove a specific element from the list, but make sure it does not affect the subsequent sorting
## Source Code
```python
# 入力の読み込み
N, K, T = map(int, input().split())
A = list(map(int, input().split()))
# 青木君の実力値を取得し、リストから除外
aoki_score = A[T - 1]
A.pop(T - 1)
# 実力値を降順にソート
A.sort(reverse=True)
# 上位 K-1 人の実力値の合計 + 青木君の実力値
total = aoki_score + sum(A[:K - 1])
# 結果の出力
print(total)
This editorial was generated by qwen3-coder-480b.
posted:
last update: