A - 商品の品質評価 / Product Quality Evaluation 解説 by admin
Qwen3-Coder-480BOverview
A problem of counting the number of products whose risk score (the product of the defect rate and the production quantity) is at least a given value \(K\).
Analysis
For each product, we calculate the product \(A_i \times B_i\) of the defect rate \(A_i\) and the production quantity \(B_i\), and determine whether it is at least \(K\).
A straightforward approach is to actually compute this product for all items and compare it. Looking at the constraints, \(A_i \leq 100\) and \(B_i \leq 10^9\), so the product can be at most around \(10^{11}\). This is within the range of the long long type (64-bit integer), so there is no issue.
Also, since \(N\) is at most \(2 \times 10^5\), even if we perform constant-time processing for each product, the overall complexity is \(O(N)\), which is sufficiently fast.
Therefore, a simple brute-force approach will run within the time limit without any special tricks.
Algorithm
- Read \(N\) and \(K\) from input.
- For each product, repeat the following:
- Read the defect rate \(A_i\) and the production quantity \(B_i\).
- Calculate the risk score \(A_i \times B_i\).
- If the value is at least \(K\), increment the count.
- Output the count.
Complexity
- Time complexity: \(O(N)\)
- Space complexity: \(O(1)\)
Implementation Notes
The product \(A_i \times B_i\) can be as large as around \(10^{11}\), so you need to either use a language with arbitrary-precision integers like Python, or use the
long longtype in languages like C++.To process the input efficiently, it is preferable to avoid unnecessary list storage and process the data while reading only the necessary information.
Source Code
N, K = map(int, input().split())
count = 0
for _ in range(N):
A, B = map(int, input().split())
if A * B >= K:
count += 1
print(count)
This editorial was generated by qwen3-coder-480b.
投稿日時:
最終更新: