A - 合格者への拍手 / Applause for the Successful Candidates Editorial by admin
GPT 5.2 HighOverview
This is a problem where you need to find the total sum of scores (= total number of claps) considering only participants whose scores are at least \(K\).
Analysis
The participants to be honored are all those whose “final score is at least \(K\)”, and the number of claps is “the same as that person’s score.” In other words, the answer equals:
- The sum of scores \(P_i\)
- for participants satisfying the condition \(P_i \ge K\).
For example, if \(K=60\) and the scores are \([40, 60, 80]\), the honored participants are the two with scores \(60\) and \(80\), and the total number of claps is \(60+80=140\).
A naive implementation that “loops \(P_i\) times for each honored participant to count” would result in at most \(100\) iterations × \(10^5\) people = about \(10^7\), which might seem feasible at first glance, but it is wasteful and misses the essence of the problem (simply computing a sum). This problem only requires computing the “sum of elements satisfying a condition,” and adding them up one by one is the most concise and reliable approach.
Algorithm
- Read \(N, K\) and the array \(P\) (each participant’s score)
- For each element \(p\) in \(P\):
- If \(p \ge K\), add \(p\) to the answer
- Output the total
In Python, you can write sum(p for p in scores if p >= K), which directly expresses “sum only the elements satisfying the condition.”
Complexity
- Time complexity: \(O(N)\) (just looking at each participant’s score once)
- Space complexity: \(O(N)\) (for storing the input score array)
Implementation Notes
Since \(N\) can be up to \(10^5\), it is safe to use fast input methods like
sys.stdin.buffer.read().The only condition check needed is
p >= K; sorting or similar operations are unnecessary.Source Code
import sys
def main():
data = list(map(int, sys.stdin.buffer.read().split()))
if not data:
return
N, K = data[0], data[1]
scores = data[2:2+N]
ans = sum(p for p in scores if p >= K)
print(ans)
if __name__ == "__main__":
main()
This editorial was generated by gpt-5.2-high.
posted:
last update: