公式

A - 合格者数 / Number of Successful Applicants 解説 by admin

Gemini 3.0 Flash

Overview

Given the test scores \(S_i\) of \(N\) students, the problem asks us to find how many students scored at least \(K\) points, which is the passing score.

Analysis

To solve this problem, we need to check each student’s score in order to determine whether it is “\(K\) points or more.”

For example, consider the case where the students’ scores are \([60, 40, 80, 70]\) and the passing score is \(60\) points. - Student 1: \(60 \ge 60\), so they pass - Student 2: \(40 < 60\), so they fail - Student 3: \(80 \ge 60\), so they pass - Student 4: \(70 \ge 60\), so they pass

In this way, by checking each student’s score exactly once, we can correctly count the total number of students who passed.

Looking at the constraints, the number of students \(N\) is at most \(2 \times 10^5\). If we use a straightforward method (linear search) that checks each student one by one, the number of operations is proportional to \(N\), which is well within the time limit.

Algorithm

We implement the program with the following steps.

  1. Read the number of students \(N\), the passing score \(K\), and each student’s score \(S_1, S_2, \ldots, S_N\) from the input.
  2. Initialize a variable count to \(0\) to keep track of the number of passing students.
  3. For each student’s score \(S_i\), repeat the following process \(N\) times:
    • If \(S_i \ge K\), add \(1\) to count.
  4. Output the final value of count.

Complexity

  • Time complexity: \(O(N)\) Since we check each student’s score exactly once, the time required is proportional to the number of students \(N\).
  • Space complexity: \(O(N)\) Since we store the \(N\) input scores as a list, the memory usage is proportional to \(N\).

Implementation Notes

  • Efficient input: In Python, when \(N\) is large (on the order of \(10^5\) or more), it is faster to read all input at once using sys.stdin.read().split() rather than calling input() multiple times.

  • Comparison operator: To check “at least \(K\) points,” use >= (greater than or equal to) instead of > (strictly greater than).

    Source Code

import sys

def main():
    # 入力を取得
    input_data = sys.stdin.read().split()
    if not input_data:
        return
    
    # N: 生徒の人数, K: 合格点
    n = int(input_data[0])
    k = int(input_data[1])
    
    # 各生徒の得点
    scores = map(int, input_data[2:])
    
    # 合格者の人数をカウント
    count = 0
    for s in scores:
        if s >= k:
            count += 1
            
    # 結果を出力
    print(count)

if __name__ == "__main__":
    main()

This editorial was generated by gemini-3-flash-preview.

投稿日時:
最終更新: