A - アルバイトの給料計算 / Calculating Part-Time Job Pay 解説 by admin
GPT 5.2 HighOverview
Since the “unit price per shift” changes depending on each staff member’s number of shifts \(C_i\), this problem asks you to calculate and sum up the salary for all staff members.
Analysis
The key point is that the special bonus \(B\) is “added to all shifts of staff members who meet the condition.”
That is, for staff member \(i\):
- If \(C_i \ge K\), the rate per shift is \(P+B\) yen
- If \(C_i < K\), the rate per shift is \(P\) yen
And the salary is simply:
- \(C_i(P+B)\) or \(C_iP\)
which can be computed in one step.
A common mistake (cause of WA) is misunderstanding the problem as “the bonus \(B\) applies only to shifts from the \(K\)-th one onward” and computing something like \((C_i-K)B\). However, in this problem, “if the number of shifts is \(K\) or more, all shifts qualify,” so if the condition is met, you add \(C_iB\) in its entirety.
Concrete example: When \(P=1000, B=200, K=5, C_i=6\):
- Correct: \(6 \times (1000+200)=7200\)
- Incorrect example: \((6 \times 1000) + (6-5)\times 200=6200\) (misinterpretation of the condition)
Algorithm
- Read \(N, P, B, K\) and each \(C_i\) as input.
- Initialize the total
totalto \(0\). - For each staff member, add the following:
- First, add the base pay \(C_i \times P\)
- Additionally, if \(C_i \ge K\), add the special bonus \(C_i \times B\)
- Output
total.
(In the code, we use the approach of “always adding \(C_iP\), and adding \(C_iB\) only when the condition is met,” which keeps the branching simple.)
Complexity
- Time complexity: \(O(N)\) (just processing each staff member once)
- Space complexity: \(O(1)\) (only storing the total; constant aside from input)
Implementation Notes
Note that the condition is “\(C_i \ge K\)” (don’t forget the equality).
The special bonus applies to “all shifts,” so the addition is \(C_i \times B\).
The maximum total amount is at most around \(100 \times 31 \times (1000+1000)=6{,}200{,}000\), so Python’s
inthandles it without issues.Source Code
import sys
def main():
data = list(map(int, sys.stdin.read().split()))
N, P, B, K = data[0], data[1], data[2], data[3]
C = data[4:4+N]
total = 0
for ci in C:
total += ci * P
if ci >= K:
total += ci * B
print(total)
if __name__ == "__main__":
main()
This editorial was generated by gpt-5.2-high.
投稿日時:
最終更新: