A - 合格者への拍手 / Applause for the Successful Candidates 解説 by admin
Qwen3-Coder-480BOverview
Among the participants, for each person whose score is \(K\) or higher, send a number of claps equal to their score. Find the total number of claps.
Discussion
In this problem, each participant’s final score \(P_i\) is given, and if a score is \(K\) or higher, we send claps equal to that score. For example, if a participant’s score is \(80\) and \(K=70\), we send \(80\) claps.
A straightforward approach is to check each participant’s score to see if it is \(K\) or higher, and if the condition is met, add that score to the total. Looking at the constraints, \(N\) is at most \(10^5\) and each score is at most \(100\), so checking all participants is more than fast enough.
This problem does not require advanced algorithms such as sorting or binary search; it can be solved with a simple linear scan.
Algorithm
- Read the number of participants \(N\) and the threshold score \(K\).
- Read each participant’s score \(P_i\) into a list.
- Iterate through the list of scores, and if a score is \(K\) or higher, add it to the total.
- Output the final total.
Complexity
- Time complexity: \(O(N)\)
- Space complexity: \(O(N)\)
Implementation Notes
Only simple conditional branching is needed for each score; no special data structures or libraries are required.
Since the range of integers is small, there is no concern about overflow.
Source Code
N, K = map(int, input().split())
P = list(map(int, input().split()))
total_claps = 0
for score in P:
if score >= K:
total_claps += score
print(total_claps)
This editorial was generated by qwen3-coder-480b.
投稿日時:
最終更新: