公式

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

GPT 5.4 High

Overview

In this problem, there is no need to consider the detailed assignment for each delivery destination. You can determine the answer simply by comparing the total number of packages with the total capacity all drivers can carry. If the total number of packages is at most \(N \times K\), delivery is possible; otherwise, it is impossible.

Analysis

At first glance, it seems like you need to consider:

  • Which driver is responsible for which delivery destination
  • How to split the packages of a single destination among multiple drivers

However, this problem has very important conditions:

  • A single driver may handle multiple delivery destinations
  • Packages for a single destination may be split among multiple drivers
  • Packages only need to be assigned in whole number units

In other words, the boundaries between delivery destinations are essentially meaningless. You can treat all packages as simply “a collection of packages.”

Key Insight

Each driver can carry up to \(K\) packages, so across all \(N\) drivers, the total capacity is at most

\(N \times K\)

packages.

On the other hand, the total number of packages that must be delivered is

\(\displaystyle \sum_{i=1}^{M} A_i\)

Therefore:

  • If \(\sum A_i \leq N \times K\), delivery is possible
  • If \(\sum A_i > N \times K\), delivery is impossible

Why This Is Sufficient

For example, even if the number of packages \(A_i\) for a certain destination is greater than \(K\), there is no problem. This is because the packages for that destination can be split among multiple drivers.

Conversely, since each driver can carry packages across multiple destinations, as long as the total capacity is sufficient, an assignment is always possible without considering detailed combinations.

Concrete Example

For example, if:

  • \(N = 3\)
  • \(K = 5\)

then the total carrying capacity is \(3 \times 5 = 15\) packages.

If the packages per destination are:

  • \(A = [4, 7, 3]\)

then the total is \(4 + 7 + 3 = 14\) packages, so delivery is possible.

In practice, the packages can be distributed, for example, as follows:

  • Driver 1: 5 packages
  • Driver 2: 5 packages
  • Driver 3: 4 packages

Since there is freedom in deciding which driver carries how many packages from which destination, there is no problem as long as the total capacity is sufficient.

Why a Naive Approach Is Unnecessary

You might be tempted to simulate “how to assign each destination,” or consider greedy algorithms or DP. However, in this problem, the degree of freedom in splitting is very high, so such complex processing is unnecessary.

All you need to do is sum up all \(M\) values of \(A_i\) and compare with \(N \times K\).

Algorithm

  1. Compute the total sum total of all \(A_i\)
  2. If total <= N * K, output Yes
  3. Otherwise, output No

Complexity

  • Time complexity: \(O(M)\)
  • Space complexity: \(O(1)\)

Implementation Notes

  • The sum of \(A_i\) can be as large as \(10^5 \times 10^9 = 10^{14}\), so depending on the language, 64-bit integers may be required.

  • In Python, there is no need to worry about integer size, so you can simply compute the sum directly.

  • Since the input provides \(A_i\) over \(M\) lines, it is sufficient to read and accumulate the sum sequentially.

    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.4-high.

投稿日時:
最終更新: