Official

A - 荷物の配送 / Package Delivery Editorial by admin

gpt-5.3-codex

Overview

Each driver can carry at most \(K\) items, so the upper limit of items that all \(N\) drivers can carry is \(N \times K\).
Therefore, this problem reduces to checking whether the total number of items across all destinations \(\sum A_i\) is within this upper limit.

Analysis

The key point of this problem is that there are effectively no per-destination constraints.
This is because:

  • Multiple drivers can share the items for the same destination
  • Items can be assigned in units of 1
  • The only constraint per driver is “at most \(K\) items in total”

In other words, there is no need to think carefully about “how many items to deliver to which destination” — it is sufficient to only consider how many items can be carried in total.


At first glance, you might be tempted to think of a method like
“simulating the process of packing each destination’s items into drivers one by one,”
but this is unnecessary.
While the constraint \(M \le 10^5\) means a simulation might fit within the time limit, the implementation becomes complex and prone to bugs.

This problem is much simpler:

  • Required number of items: \(S = \sum_{i=1}^{M} A_i\)
  • Maximum number of items that can be carried: \(C = N \times K\)

If \(S \le C\), output Yes; otherwise, output No.

Example: - If \(N=3, K=4\), at most \(12\) items can be carried - If the total number of items is \(10\), it is possible (Yes) - If the total number of items is \(13\), it is impossible (No)

Algorithm

  1. Read \(N, M, K\).
  2. Sum all \(M\) values of \(A_i\) to compute total.
  3. If total <= N * K, output Yes; otherwise, output No.

Complexity

  • Time complexity: \(O(M)\)
  • Space complexity: \(O(1)\) (items are accumulated on the fly, so no array storage is needed)

Implementation Notes

  • The sum and \(N \times K\) can become large, so be careful about overflow depending on the language (Python is safe due to arbitrary-precision integers).

  • Instead of storing \(A_i\) in an array, adding each value to total on the spot is more memory-efficient.

  • Since the input can be large, using sys.stdin.readline in the implementation is appropriate.

    Source Code

import sys

def main():
    input = sys.stdin.readline
    N, M, K = map(int, input().split())
    total = 0
    for _ in range(M):
        total += int(input())
    print("Yes" if total <= N * K else "No")

if __name__ == "__main__":
    main()

This editorial was generated by gpt-5.3-codex.

posted:
last update: