Official

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

DeepSeek V3

Overview

This is a problem where you calculate the base pay and special bonus based on each part-time staff member’s number of shifts, then find the total salary for all staff.

Analysis

The problem conditions are simple: the pay rate per shift changes depending on whether each staff member’s number of shifts \(C_i\) meets or exceeds the threshold \(K\). If \(C_i \geq K\), the pay is \((P + B)\) yen per shift; otherwise, it is \(P\) yen per shift. We simply need to calculate each staff member’s salary using conditional branching and sum them all up. Since the input size is at most \(N \leq 100\), which is small, a straightforward loop is sufficiently efficient.

Algorithm

  1. First, read \(N\), \(P\), \(B\), \(K\) from the first line of input
  2. Read the list of shift counts \(C\_list\) for each staff member from the second line of input
  3. Initialize the total salary total_salary to 0
  4. Loop over each staff member’s shift count \(C\):
    • If \(C \geq K\): add \(C \times (P + B)\) to the total
    • If \(C < K\): add \(C \times P\) to the total
  5. Output the calculated total salary

Complexity

  • Time complexity: \(O(N)\)
    • Because we perform constant-time operations for each of the \(N\) staff members
  • Space complexity: \(O(N)\)
    • Because we store the list of shift counts

Implementation Notes

  • The conditional branching is done with if C >= K:, and it is important to include the equality (since the problem states “\(K\) shifts or more”)

  • Input reading uses map(int, input().split()) for efficient numeric conversion

  • Using meaningful variable names improves code readability (e.g., total_salary, C_list)

    Source Code

def main():
    data = list(map(int, input().split()))
    N, P, B, K = data
    C_list = list(map(int, input().split()))
    
    total_salary = 0
    for C in C_list:
        if C >= K:
            total_salary += C * (P + B)
        else:
            total_salary += C * P
            
    print(total_salary)

if __name__ == "__main__":
    main()

This editorial was generated by deepseekv3.

posted:
last update: