公式

A - バッテリー残量と充電器の到着 / Battery Level and Charger Arrival 解説 by admin 印刷ページ

Qwen3-Coder-480B

Overview

Given the battery levels and drain rates of smartphones, and the number of days until a charger arrives, determine how many smartphones are still usable when the charger arrives.

Analysis

For each smartphone, it is considered “usable” if its battery does not reach \(0\) by the time the charger arrives \(K\) days later, and its battery level is at least \(1\) at that point.

A straightforward approach might be to simulate day by day, but since \(K\) can be as large as \(10^9\), processing each day individually would not finish in time (TLE).

However, since each smartphone’s battery level simply decreases at a constant rate, we can directly calculate the final remaining battery.
Specifically, the final battery level is obtained by subtracting \(D \times K\) (the drain per day times the number of days) from the initial battery level \(W_i\): $\( \text{Final battery level} = W_i - D \times K \)\( If this value is \)1$ or more, the smartphone remains in a usable state.

Therefore, the answer can be obtained by simply checking this condition for each smartphone.

Example

For instance, when \(W_i = 10\), \(D = 3\), \(K = 3\): $\( 10 - 3 \times 3 = 10 - 9 = 1 \)\( This is \)1$, so this smartphone barely remains usable.

On the other hand, when \(W_i = 9\): $\( 9 - 3 \times 3 = 0 \)\( This is \)0$, so it is not usable (the phone has shut off).

Algorithm

  1. Read the initial battery level \(W_i\) for each smartphone.
  2. For each \(W_i\), calculate the final battery level \(W_i - D \times K\).
  3. If the final battery level is \(1\) or more, increment the count.
  4. Output the count.

Complexity

  • Time complexity: \(O(N)\)
  • Space complexity: \(O(N)\)

※ \(N\) is the number of smartphones. Since each smartphone only needs to be checked once, processing can be done in linear time.

Implementation Notes

  • Since each smartphone’s battery level can be evaluated independently, it suffices to check them one by one in a loop.

  • Note that the condition is “final battery level is 1 or more” (0 is not acceptable).

  • Since large values are involved (\(K\) can be up to \(10^9\)), overflow should be kept in mind. However, in Python, this can be computed without any special concern.

    Source Code

N, D, K = map(int, input().split())
W = list(map(int, input().split()))

count = 0
for w in W:
    if w - D * K >= 1:
        count += 1

print(count)

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

投稿日時:
最終更新: