公式

A - アルバイトの給料計算 / Calculating Part-Time Job Pay 解説 by admin

Qwen3-Coder-480B

Overview

This is a problem where you calculate the total salary a company must pay based on the number of shifts each part-time staff member has worked.

Analysis

In this problem, depending on the number of shifts \(C_i\) each staff member has worked, it is determined whether they receive a special bonus on top of their base pay. Specifically, if the number of shifts is \(K\) or more, the pay per shift becomes \(P + B\) yen; otherwise, it is \(P\) yen.

Therefore, for each staff member, one of the following calculations must be performed: - When \(C_i \geq K\): Salary = \(C_i \times (P + B)\) - When \(C_i < K\): Salary = \(C_i \times P\)

Since we just need to perform this process for all staff members, no particularly complex conditional branching or optimization is required, and the problem can be solved with a straightforward simulation. For example, if staff A has worked 5 shifts and the threshold is \(K=5\), the special bonus applies, so the rate of \(P+B\) yen per shift is used.

Algorithm

  1. Read \(N, P, B, K\) and each staff member’s number of shifts \(C_i\) from the input.
  2. For each staff member, calculate the salary as follows:
    • If the number of shifts \(C_i \geq K\), then \(C_i \times (P + B)\)
    • Otherwise, \(C_i \times P\)
  3. Sum up the salaries for all staff members and output the result.

Complexity

  • Time complexity: \(O(N)\)
  • Space complexity: \(O(N)\)

Implementation Notes

  • Use conditional branching (if) to correctly determine whether the special bonus applies.

  • The variable holding the total amount should be initialized to 0 at the beginning.

    Source Code

# 入力の受け取り
N, P, B, K = map(int, input().split())
C = list(map(int, input().split()))

# 給料の合計を計算
total_salary = 0
for c in C:
    if c >= K:
        # 特別手当が適用される場合
        total_salary += c * (P + B)
    else:
        # 基本給のみの場合
        total_salary += c * P

# 結果の出力
print(total_salary)

This editorial was generated by qwen3-coder-480b.

投稿日時:
最終更新: