Official

A - フリーランスの報酬 / Freelance Compensation Editorial by admin

gemini-3.5-flash-thinking

Overview

This problem requires you to sum up the rewards of projects (out of \(N\) given projects) that can be delivered within a deadline of \(M\) days, then subtract a \(P\)% commission fee to find the final take-home amount.

Analysis

1. Which projects should be accepted?

Takahashi wants to calculate his income over the next \(M\) days. Completing project \(i\) takes \(D_i\) days. Therefore, the condition for a project to be completed within \(M\) days is: $\(D_i \leq M\)$

The sum of rewards \(V_i\) for all projects satisfying this condition is the total reward \(S\). Projects that do not satisfy the condition (\(D_i > M\)) cannot be completed within the time period, so no reward is earned from them and they can be ignored.

2. Commission calculation and avoiding floating-point errors

We calculate the amount after subtracting the \(P\)% commission from the total reward \(S\). The percentage that remains is \((100 - P)\)%. Therefore, the desired amount is expressed as: $\(\text{take-home amount} = S \times \frac{100 - P}{100}\)$

In programming, if you compute this as S * (100 - P) / 100 using floating-point numbers (decimals), rounding errors can occur, which may prevent you from obtaining the correct integer value. Since this problem requires outputting “an integer with the fractional part truncated,” we can completely avoid errors by using integer division (floor division) as follows: $\(\text{ans} = (S \times (100 - P)) \text{ // } 100\)$ Note: // is Python’s floor division operator.

Algorithm

  1. Initialize a variable \(S\) to \(0\) to hold the total reward.
  2. For each project \(i\) (\(1 \leq i \leq N\)), perform the following:
    • If \(D_i \leq M\), add \(V_i\) to \(S\).
  3. After scanning all projects, compute \(S \times (100 - P) \text{ // } 100\) and output the result.

Complexity

  • Time complexity: \(O(N)\) We iterate through the loop only once to evaluate each of the \(N\) projects, so the processing completes in \(O(N)\) time. Since \(N \le 2 \times 10^5\), this runs well within the typical time limit of 2 seconds.
  • Space complexity: \(O(N)\) Since the input is read all at once and stored in a list, memory proportional to the input size is used.

Implementation Notes

  • Fast input processing: In Python, when the number of inputs is large (\(N \le 2 \times 10^5\)), calling input() repeatedly can result in long execution times. By using sys.stdin.read().split() to read all input at once, processing can be done much faster.

  • Integer arithmetic: As discussed in the analysis, by computing S * (100 - P) // 100 without any intermediate floating-point calculations, we can safely and accurately obtain the integer with the fractional part truncated.

    Source Code

import sys

def main():
    # 入力をすべて取得
    input_data = sys.stdin.read().split()
    if not input_data:
        return
    
    N = int(input_data[0])
    M = int(input_data[1])
    P = int(input_data[2])
    
    S = 0
    # 各案件の情報を処理
    for i in range(3, 3 + 2 * N, 2):
        d = int(input_data[i])
        v = int(input_data[i+1])
        if d <= M:
            S += v
            
    # 手数料を差し引いた金額を計算(小数点以下切り捨て)
    ans = S * (100 - P) // 100
    print(ans)

if __name__ == '__main__':
    main()

This editorial was generated by gemini-3.5-flash-thinking.