公式

A - 訓練メニューの消化 / Completing the Training Menu 解説 by admin

Qwen3-Coder-480B

Overview

Given the remaining count for each exercise, determine whether it is possible to complete a total of \(M\) training sessions, where each training session consumes \(K\) repetitions of a chosen exercise.

Analysis

In this problem, what matters for each exercise is “how many training sessions it can be used for.”
For example, if an exercise has \(A_i\) remaining repetitions and each training session requires \(K\) repetitions, then that exercise can be used for at most \(\left\lfloor \frac{A_i}{K} \right\rfloor\) training sessions.

Therefore, we compute this value for all exercises and check whether the total sum is at least \(M\). If so, \(M\) days of training are possible.

A naive approach of simulating “which exercise to use each day” would be inefficient. In particular, since \(M\) can be up to \(10^9\), simulating day by day would not finish in time (TLE).
Also, an important point is that exercises with fewer than \(K\) remaining repetitions cannot be used at all, so they can be ignored.

The key insight of this problem is that it is sufficient to just look at the “total number of usable sessions.”

Algorithm

  1. For each exercise’s remaining count \(A_i\), compute \(\left\lfloor \frac{A_i}{K} \right\rfloor\).
  2. If this value is 1 or more, that exercise contributes usable training sessions.
  3. Sum up these “usable session counts” across all exercises.
  4. If the total is at least \(M\), output Yes; otherwise, output No.

Complexity

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

Implementation Notes

  • For each \(A_i\), add \(\left\lfloor \frac{A_i}{K} \right\rfloor\) only when \(A_i \geq K\).
  • It is sufficient to simply compare whether the total is at least \(M\) at the end.
  • Using fast input reading (e.g., sys.stdin.read) is recommended (especially when \(N\) is large).
## Source Code

```python
import sys
import heapq

def main():
    input = sys.stdin.read
    data = input().split()
    
    N = int(data[0])
    M = int(data[1])
    K = int(data[2])
    A = list(map(int, data[3:]))

    # 各エクササイズが何回トレーニングに使えるかを計算
    usable = []
    for a in A:
        if a >= K:
            usable.append(a // K)
    
    # 使える回数の合計がM以上ならOK
    total = sum(usable)
    if total >= M:
        print("Yes")
    else:
        print("No")

if __name__ == "__main__":
    main()

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

投稿日時:
最終更新: