公式

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

gpt-5.5-high

Overview

This problem asks you to sum the rewards of only the projects that can be delivered within \(M\) days, then subtract a commission of \(P\%\) from that total.

Analysis

The condition for project \(i\) to be completed within \(M\) days is that the number of days until delivery \(D_i\) satisfies

\(D_i \leq M\)

Therefore, we check this condition for all projects and sum up only the rewards \(V_i\) of projects that satisfy it.

For example, when \(M = 10\):

Project \(D_i\) \(V_i\) Eligible?
1 5 1000 Yes
2 12 2000 No
3 10 3000 Yes

In this case, the total reward is

\(1000 + 3000 = 4000\)

From this, we subtract the commission of \(P\%\), so the actual amount received is

\(4000 \times \frac{100 - P}{100}\)

The answer needs to be truncated (rounded down), but using integer division naturally achieves this truncation.

About the naive approach

If you consider a method like “simulating from day 1 to day \(M\)”, since \(M\) can be up to \(10^9\), this would be too slow.

However, in this problem, it is sufficient to only determine whether each project “finishes within \(M\) days or not.”
Therefore, day-by-day simulation is unnecessary, and the problem can be solved by simply examining each project one by one.

Algorithm

  1. Read \(N, M, P\).
  2. Initialize a variable sum representing the total reward to \(0\).
  3. For each project, read \(D_i, V_i\).
  4. If \(D_i \leq M\), the project is completed within \(M\) days, so add \(V_i\) to sum.
  5. Calculate the amount after subtracting the commission.

Specifically, the remaining percentage after subtracting the commission is

\(100 - P\)

percent, so the answer is

\(sum \times \frac{100 - P}{100}\)

For integer computation, the implementation is as follows:

\(ans = sum \times (100 - P) / 100\)

This division truncates the decimal part.

Complexity

  • Time complexity: \(O(N)\)
  • Space complexity: \(O(1)\)

Implementation Notes

The total reward can be as large as

\(2 \times 10^5 \times 10^6 = 2 \times 10^{11}\)

so it does not fit in an int.
Therefore, use long long for the total and computed results.

Also, for the commission calculation:

long long ans = sum * (100 - P) / 100;

By performing the multiplication first and then the division like this, you correctly obtain the truncated (floor) result.

Source Code

#include <bits/stdc++.h>
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int N;
    long long M;
    long long P;
    cin >> N >> M >> P;

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

    long long ans = sum * (100 - P) / 100;
    cout << ans << '\n';

    return 0;
}

This editorial was generated by gpt-5.5-high.

投稿日時:
最終更新: