A - アルバイトの給料計算 / Calculating Part-Time Job Pay 解説 by admin
Claude 4.6 Opus (Thinking)Overview
This is a problem where, based on the number of shifts each part-time staff member works, you determine whether they receive only the base pay or the base pay plus a special bonus, and then calculate the total salary for all staff members.
Analysis
In this problem, each staff member’s salary is determined by one of the following two patterns:
- Number of shifts \(C_i\) is \(K\) or more → \((P + B)\) yen per shift
- Number of shifts \(C_i\) is less than \(K\) → \(P\) yen per shift
In other words, for each staff member, you check whether their number of shifts meets the threshold of \(K\) or more, then multiply the corresponding unit price by their number of shifts to obtain the payment for that staff member.
Let’s verify with a concrete example.
For instance, with \(N = 3\), \(P = 100\), \(B = 50\), \(K = 5\), and shift counts \(C = [3, 5, 8]\):
| Staff | Shifts | \(\geq K\)? | Unit Price | Payment |
|---|---|---|---|---|
| 1 | 3 | No | \(100\) yen | \(3 \times 100 = 300\) yen |
| 2 | 5 | Yes | \(150\) yen | \(5 \times 150 = 750\) yen |
| 3 | 8 | Yes | \(150\) yen | \(8 \times 150 = 1200\) yen |
Total: \(300 + 750 + 1200 = 2250\) yen
The constraints in this problem are small (\(N \leq 100\)), so simply processing all staff members in a loop is sufficient. No special techniques or algorithms are needed — a straightforward approach solves the problem without any issues.
Algorithm
- Read \(N\), \(P\), \(B\), \(K\), and each staff member’s number of shifts \(C_1, C_2, \ldots, C_N\) from input.
- Initialize the total amount
totalto \(0\). - For each staff member \(i\):
- If \(C_i \geq K\), add \(C_i \times (P + B)\) to
total. - If \(C_i < K\), add \(C_i \times P\) to
total.
- If \(C_i \geq K\), add \(C_i \times (P + B)\) to
- Output
total.
Complexity
- Time complexity: \(O(N)\) — We only perform one check and calculation per staff member.
- Space complexity: \(O(N)\) — For storing the list of shift counts (this can be reduced to \(O(1)\) if values are read and processed one at a time).
Implementation Notes
Be careful that the condition is “\(K\) or more.” Use
>=(not>).The special bonus is “added on top of the base pay,” so the unit price for staff with \(K\) or more shifts is \(P + B\). Be careful not to overlook that the base pay \(P\) is also included — it is not just the special bonus \(B\) alone.
Source Code
N, P, B, K = map(int, input().split())
C = list(map(int, input().split()))
total = 0
for c in C:
if c >= K:
total += c * (P + B)
else:
total += c * P
print(total)
This editorial was generated by claude4.6opus-thinking.
投稿日時:
最終更新: