A - アルバイトの給料計算 / Calculating Part-Time Job Pay Editorial by admin
gpt-5.3-codexOverview
This is a problem where you calculate “hourly wage × hours” for each part-time job and sum them all up to find the total salary for the month. In other words, you simply need to compute \( \sum_{i=1}^{N} A_i T_i \).
Analysis
The essence of this problem is very simple. The pay for each job is given by: \(A_i\) (hourly wage) \(\times\) \(T_i\) (hours worked)
Therefore, the total salary is the following sum:
\[ A_1T_1 + A_2T_2 + \cdots + A_NT_N \]
Key Observations
- The information for each part-time job is independent, so you can read one line at a time and accumulate the sum as you go.
- There is no need to store everything in an array; you can add to the total on the spot.
Notes on the Straightforward Approach
No special tricks are needed for this problem. Since \(N \le 10^5\), computing each term one at a time is fast enough. In fact, unnecessarily complex processing (such as nested loops) could make the solution slower for no reason.
Also, considering the maximum values:
\(A_iT_i \le 10^6 \times 10^6 = 10^{12}\),
and summing up to \(10^5\) such values means the total can be at most around \(10^{17}\).
Python’s int can handle large integers, so there is no issue.
Algorithm
- Read \(N\).
- Initialize the total
totalto 0. - Repeat \(N\) times:
- Read \(A, T\)
- Perform
total += A * T
- Output
total.
Complexity
- Time complexity: \(O(N)\)
- Space complexity: \(O(1)\)
Implementation Notes
Since there are many input lines, using
input = sys.stdin.readlineis faster and more stable.By accumulating the sum incrementally without storing values in an array, memory usage is kept low.
In Python, you can compute the products and total sum without worrying about overflow.
Source Code
import sys
def main():
input = sys.stdin.readline
N = int(input())
total = 0
for _ in range(N):
A, T = map(int, input().split())
total += A * T
print(total)
if __name__ == "__main__":
main()
This editorial was generated by gpt-5.3-codex.
posted:
last update: