Official

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

Claude 4.6 Opus (Thinking)

Overview

For each of the \(N\) types of part-time jobs, calculate “hourly wage × hours worked” and find the total sum.

Analysis

This problem is a straightforward calculation problem. The salary earned from each part-time job is given by “hourly wage \(A_i\) × hours \(T_i\)”, so we just need to sum this across all job types.

For example, consider the following input:

3
1000 8
1200 5
900 3
  • 1st part-time job: \(1000 \times 8 = 8000\) yen
  • 2nd part-time job: \(1200 \times 5 = 6000\) yen
  • 3rd part-time job: \(900 \times 3 = 2700\) yen
  • Total: \(8000 + 6000 + 2700 = 16700\) yen

No complex algorithm is needed — simply summing up the values in a loop is sufficient.

Regarding overflow: Since the maximum values of \(A_i\) and \(T_i\) are each \(10^6\), a single part-time job can yield up to \(10^{12}\) yen, and since \(N\) can be up to \(10^5\), the total can be on the order of \(10^{17}\). In C++ and similar languages, you need to use long long, but in Python, integers have no upper limit, so there is no need to worry about this.

Algorithm

  1. Read \(N\).
  2. Initialize a variable total to \(0\) to hold the total amount.
  3. Loop \(N\) times, reading \(A_i\) and \(T_i\) from each line, and add \(A_i \times T_i\) to total.
  4. Output total.

Expressed as a formula, the desired answer is:

\[\text{Total} = \sum_{i=1}^{N} A_i \times T_i\]

Complexity

  • Time complexity: \(O(N)\) — We only perform one multiplication and one addition for each part-time job.
  • Space complexity: \(O(1)\) — We only need a single variable to hold the total (there is no need to store the input).

Implementation Notes

  • In Python, there is no need to worry about integer overflow, so simply adding up A * T will give the correct result.

  • The information for each part-time job can be read line by line and used in the calculation immediately, without needing to store it in an array. This keeps the space complexity at \(O(1)\).

    Source Code

N = int(input())
total = 0
for _ in range(N):
    A, T = map(int, input().split())
    total += A * T
print(total)

This editorial was generated by claude4.6opus-thinking.

posted:
last update: