A - フリーランスの報酬 / Freelance Compensation 解説 by admin
gpt-5.5-highOverview
Among \(N\) tasks, we consider only those whose delivery deadline \(D_i\) is within \(M\) days, and compute the total of their rewards \(V_i\).
We then subtract a fee of \(P\) percent from that total and output the result, rounded down (floor).
Analysis
Whether task \(i\) will be completed within the next \(M\) days can be determined simply by checking whether
\(D_i \leq M\)
is satisfied.
Therefore, we just need to check each task one by one and sum up the rewards of only those tasks that satisfy the condition.
For example, when \(M = 10\):
| Task | \(D_i\) | \(V_i\) | Eligible? |
|---|---|---|---|
| 1 | 5 | 1000 | Yes |
| 2 | 12 | 3000 | No |
| 3 | 10 | 2000 | Yes |
In this case, the total reward is
\(1000 + 2000 = 3000\)
From this, we subtract a fee of \(P\) percent, so the final amount received is
\(3000 \times \frac{100 - P}{100}\)
The answer must be rounded down (floor).
Therefore, we can compute it using integer division:
\(total \times (100 - P) // 100\)
If you consider a naive approach like “simulating from day 1 to day \(M\)”, since \(M\) can be as large as \(10^9\), the execution time would not be sufficient.
However, in this problem, it is enough to simply check whether \(D_i \leq M\) for each task, so a day-by-day simulation is unnecessary.
Algorithm
- Read \(N, M, P\).
- Initialize a variable
totalrepresenting the total reward to \(0\). - For each task, read \(D_i, V_i\).
- If \(D_i \leq M\), then that task will be completed within \(M\) days, so add \(V_i\) to
total. - Finally, output the amount after subtracting the fee
\(total \times \frac{100 - P}{100}\)
rounded down (floor).
Using integer arithmetic, this can be written as:
\(total \times (100 - P) // 100\)
Complexity
- Time complexity: \(O(N)\)
- Space complexity: \(O(1)\)
Implementation Notes
Only tasks with \(D_i \leq M\) are included in the total.
Since the amount after subtracting the fee must be rounded down (floor), we use integer division with
//.The total reward can be as large as \(2 \times 10^5 \times 10^6 = 2 \times 10^{11}\), so in other languages, a 64-bit integer type is required. In Python, there is no need to worry about integer overflow.
Source Code
import sys
def main():
input = sys.stdin.buffer.readline
N, M, P = map(int, input().split())
total = 0
for _ in range(N):
D, V = map(int, input().split())
if D <= M:
total += V
print(total * (100 - P) // 100)
if __name__ == "__main__":
main()
This editorial was generated by gpt-5.5-high.
投稿日時:
最終更新: