B - 成績表の更新 / Updating the Report Card Editorial by admin
Claude 4.5 OpusOverview
This is a problem where you perform multiple updates on a list of student scores and count how many students have scores below a threshold at the end.
Analysis
Problem Breakdown
In this problem, we perform the following steps: 1. Receive the initial scores of \(N\) students 2. Apply \(M\) updates (rewriting specific students’ scores) in order 3. Count the number of students with scores below \(K\) at the end
Key Observations
- Note that the same student may be updated multiple times
- For example, if student 1’s score is updated “50→70→30” twice, the final score is 30
- In other words, by applying each update in order, the score is naturally overwritten to the latest value
Why This Problem is Easy
- No complex algorithms are needed; simply simulating (processing as instructed) is sufficient
- Since each update only rewrites the corresponding position in the array, it can be processed in \(O(1)\)
Algorithm
Initialization: Store the students’ scores in array
QUpdate Processing: Process \(M\) updates in order
- For each update, rewrite student number \(P\)’s score to \(V\)
- Since student numbers start from 1 (1-indexed), convert to array index (0-indexed) by using
P - 1
Counting: Traverse the final array
Qand count the number of students with scores below \(K\)
Concrete Example
Sample input: \(N=3, M=2, K=50\), initial scores \([40, 60, 30]\) - Update 1: Change student 1’s score to 55 → \([55, 60, 30]\) - Update 2: Change student 3’s score to 70 → \([55, 60, 70]\) - Number of students below 50 points is 0
Complexity
Time Complexity: \(O(N + M)\)
- Reading initial scores: \(O(N)\)
- \(M\) update operations: Each is \(O(1)\), so total is \(O(M)\)
- Final counting: \(O(N)\)
Space Complexity: \(O(N)\)
- Only the array storing students’ scores
Implementation Notes
Index Conversion: While student numbers start from 1 (1-indexed) in the problem statement, Python arrays start from 0 (0-indexed), so adjustment like
Q[P - 1]is necessaryWhen Number of Updates is 0: \(M = 0\) is possible, but since the for loop simply executes 0 times, no special handling is needed
How to Write the Count: In Python, using a generator expression like
sum(1 for score in Q if score < K)is concise.len([score for score in Q if score < K])gives the same result
Source Code
# Receive input
N, M, K = map(int, input().split())
Q = list(map(int, input().split()))
# Process M updates
for _ in range(M):
P, V = map(int, input().split())
Q[P - 1] = V # Adjust since student numbers are 1-indexed
# Count the number of students with scores below K
count = sum(1 for score in Q if score < K)
# Output the result
print(count)
This editorial was generated by claude4.5opus.
posted:
last update: