Official

B - テストの目標点 / Target Score for the Test Editorial by admin

Qwen3-Coder-480B

Overview

This problem asks us to find the minimum number of additional assignments needed for Takahashi to bring each subject’s score up to the target score \(T\) or above, and output it if it is within the submittable limit \(M\).

Analysis

In this problem, if the score \(A_i\) for each subject \(i\) falls below the target score \(T\), then \(T - A_i\) additional assignments are needed. In other words, the total of “deficit points to reach the target” across all subjects gives us the total number of additional assignments required.

For example, if \(N = 3\), \(T = 80\), \(A = [70, 85, 75]\): - Subject 1: short by \(80 - 70 = 10\) points - Subject 2: \(85 \geq 80\), so OK - Subject 3: short by \(80 - 75 = 5\) points → A total of \(10 + 5 = 15\) additional assignments are needed.

If this total is \(M\) or less, supplementary lessons can be avoided; if it exceeds \(M\), it is impossible, so we output -1.

A naive approach of simulating one point at a time is conceivable, but since \(M\) can be up to \(10^9\), this is impractical. However, since we only need to look at the total required points, we can solve it efficiently.

Algorithm

  1. For each subject \(i\), if \(T - A_i\) is positive, that many points need to be made up.
  2. Sum up these “deficit points” across all subjects.
  3. If the total is \(M\) or less, output that value; otherwise, output -1.

Specifically, we perform the following calculation: $\( \text{needed\_points} = \sum_{i=1}^{N} \max(0, T - A_i) \)$

Complexity

  • Time complexity: \(O(N)\)
  • Space complexity: \(O(1)\) (excluding input data)

Implementation Notes

  • By using max(0, T - a), subjects that already exceed the target score are ignored.

  • We only need to check at the end whether the total exceeds \(M\).

    Source Code

N, M, T = map(int, input().split())
A = list(map(int, input().split()))

# 目標点T未満の科目に対して、何点足りないかを計算
needed_points = sum(max(0, T - a) for a in A)

# 必要な追加課題数がM以下なら可能
if needed_points <= M:
    print(needed_points)
else:
    print(-1)

This editorial was generated by qwen3-coder-480b.

posted:
last update: