公式

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

gemini-3.5-flash-thinking

Overview

This problem asks you to find the total reward of jobs whose delivery days are \(M\) days or fewer among the given \(N\) jobs, and then calculate the take-home amount after deducting the specified commission fee of \(P\)%.

Analysis

First, let’s organize the conditions for jobs that Takahashi can deliver within \(M\) days. For a job \(i\) to be completed within \(M\) days, the number of days required for delivery \(D_i\) must be at most \(M\) (\(D_i \le M\)).

Therefore, the procedure to solve the problem can be broken down into the following 2 steps: 1. Check the \(N\) jobs in order and calculate the total sum \(S\) of rewards \(V_i\) for jobs satisfying \(D_i \le M\). 2. Calculate the amount after deducting the \(P\)% commission fee from the total sum \(S\).

Commission Fee Calculation

Since the commission fee is \(P\)%, the amount remaining for Takahashi is \((100 - P)\)% of the total. Expressed as a formula, this is: $\( \text{Take-home amount} = S \times \frac{100 - P}{100} \)\( According to the problem statement, the result must be rounded down (truncated) at the decimal point. In many programming languages such as C++, integer division (the `/` operator) automatically truncates the decimal part for operations between positive numbers (behaving the same as the floor function \)\lfloor \dots \rfloor$), so computing S * (100 - P) / 100 directly gives the correct answer.

Note on Overflow (Important)

Checking the constraints, the number of jobs \(N\) is at most \(2 \times 10^5\), and each job’s reward \(V_i\) is at most \(10^6\). If all jobs satisfy the condition, the total sum of rewards \(S\) can reach up to \(2 \times 10^5 \times 10^6 = 2 \times 10^{11}\). The maximum value that a typical 32-bit integer type (such as int in C++) can represent is approximately \(2 \times 10^9\), so using int type would cause overflow (a phenomenon where the number exceeds the representable range and becomes an incorrect value). Therefore, for the variable holding the total sum and during calculations, you need to use a 64-bit integer type (such as long long in C++) that can handle larger values.

Algorithm

  1. Initialize a variable total_reward to 0 to hold the total sum of rewards (type: long long).
  2. Read the information \(D_i, V_i\) for each job sequentially from input.
  3. If \(D_i \le M\) is satisfied, add \(V_i\) to total_reward.
  4. After processing all jobs, compute total_reward * (100 - P) / 100 and output the result.

Complexity

  • Time complexity: \(O(N)\) Since we check each job’s information once in a loop, the processing completes in time proportional to the number of jobs \(N\). Since \(N \le 2 \times 10^5\), this is sufficiently fast for the time limit.
  • Space complexity: \(O(1)\) Since we do not store the input in arrays but instead judge and accumulate on the fly, the memory usage is only a constant amount for a few variables.

Implementation Notes

  • Fast I/O: In C++, since the number of input data items \(N\) can be as large as \(2 \times 10^5\), using cin.tie(NULL) and ios_base::sync_with_stdio(false) to speed up I/O can reduce execution time.

  • Appropriate type selection: By declaring not only the total reward but also variables used during computation such as \(M\) and \(P\) as long long type, you can prevent bugs from type conversion and overflow in advance.

    Source Code

#include <iostream>

using namespace std;

int main() {
    // 高速な入出力
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int N;
    long long M, P;
    if (!(cin >> N >> M >> P)) return 0;

    long long total_reward = 0;
    for (int i = 0; i < N; ++i) {
        long long D, V;
        cin >> D >> V;
        if (D <= M) {
            total_reward += V;
        }
    }

    // 手数料を差し引いた金額を計算(小数点以下切り捨て)
    long long ans = total_reward * (100 - P) / 100;

    cout << ans << "\n";

    return 0;
}

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