Official

D - 突出したスコア / Outstanding Score Editorial by admin Editorial for printing

DeepSeek V3

Overview

This is a problem where we need to find the number of students who satisfy the given condition: “scoring at least \(K\) times the average score of all other students.”

Analysis

Let’s transform the inequality given in the problem: \(A_i \times (N - 1) \geq K \times (S - A_i)\), where \(S\) is the total score of all students.

Rearranging this inequality: \(A_i \times (N - 1) \geq K \times (S - A_i)\) \(A_i \times (N - 1) \geq K \times S - K \times A_i\) \(A_i \times (N - 1) + K \times A_i \geq K \times S\) \(A_i \times (N - 1 + K) \geq K \times S\)

Through this transformation, we can see that the condition for each student \(i\) can be concisely expressed as \(A_i \times (N - 1 + K) \geq K \times S\). However, the original inequality can also be computed efficiently enough as-is.

In a straightforward approach, we first compute the total score \(S\) of all students (\(O(N)\)), then check the inequality for each student (\(O(N)\)). This allows us to solve the problem in \(O(N)\) overall. Since the constraint is \(N \leq 2 \times 10^5\), this linear-time algorithm is sufficiently efficient.

Algorithm

  1. Read \(N\), \(K\), and the score list \(A\) from input
  2. If \(N = 1\), the condition is always satisfied, so output \(1\) and terminate
  3. Compute the total score \(S\) of all students
  4. For each student \(i\), check the inequality \(A_i \times (N - 1) \geq K \times (S - A_i)\)
  5. Count and output the number of students who satisfy the condition

Complexity

  • Time complexity: \(O(N)\)
    • \(O(N)\) for computing the total score
    • \(O(N)\) for checking each student
  • Space complexity: \(O(N)\)
    • Memory required to store the score list

Implementation Notes

  • The case \(N = 1\) needs to be handled specially (to prevent division by zero in the denominator)

  • Since everything can be processed using only integer arithmetic, there is no need to worry about floating-point precision errors

  • Multiplications involving large numbers (up to approximately \(10^9 \times 10^9 = 10^{18}\)) may occur, but in Python, integers are automatically handled as arbitrary-precision integers, so this is not an issue

    Source Code

import sys

def main():
    data = sys.stdin.read().split()
    n = int(data[0])
    K = int(data[1])
    A = list(map(int, data[2:2+n]))
    
    if n == 1:
        print(1)
        return
        
    total = sum(A)
    count = 0
    
    for a in A:
        if a * (n - 1) >= K * (total - a):
            count += 1
            
    print(count)

if __name__ == "__main__":
    main()

This editorial was generated by deepseekv3.

posted:
last update: