Official

A - 荷物の積載 / Loading Cargo Editorial by admin Editorial for printing

GPT 5.2 High

Overview

For each truck, determine the maximum number of items \(r_i\) that can be loaded while satisfying both the “weight limit \(T\)” and the “quantity limit \(R\)”.

Analysis

The conditions for loading \(k\) items onto truck \(i\) are the following two:

  • Weight limit: \(P_i \times k \leq T\)
  • Quantity limit: \(k \leq R\)

From the weight limit, the upper bound on the number of items that can be loaded is $\( k \leq \left\lfloor \frac{T}{P_i} \right\rfloor \)$ (floored since it must be an integer).

Therefore, the maximum number satisfying both limits simultaneously is $\( r_i = \min\left(R,\ \left\lfloor \frac{T}{P_i} \right\rfloor\right) \)$

A naive approach of “loading items one by one and counting until a limit is reached” would require up to \(R\) operations per truck (up to \(10^9\)), and since \(N\) can be up to \(2 \times 10^5\), this is far too slow (TLE).
However, using the formula above, each truck’s answer can be computed with a single division.

Example: - When \(T=10,\ R=7,\ P_i=3\), the weight limit alone allows \(\left\lfloor 10/3 \right\rfloor=3\) items. Since this is less than the quantity limit \(7\), we get \(r_i=\min(7,3)=3\).

Algorithm

  1. Read \(N, R, T\) and the array \(P\) as input.
  2. For each truck \(i\), compute \(x = T // P_i\) (integer division).
  3. Output \(r_i = \min(R, x)\) as the answer.

Complexity

  • Time complexity: \(O(N)\) (constant time per truck)
  • Space complexity: \(O(N)\) (for the input array and output array)

Implementation Notes

  • \(T\) can be up to \(10^{18}\), so depending on the language, 64-bit integers are required (Python uses arbitrary-precision integers, so it’s safe).

  • Since \(N\) can be large, in Python it’s recommended to use fast input methods like sys.stdin.buffer.read() for stability.

  • Since we need the floored quotient, use T // p (integer division).

    Source Code

import sys

def main():
    data = list(map(int, sys.stdin.buffer.read().split()))
    N, R, T = data[0], data[1], data[2]
    P = data[3:3+N]
    res = [str(min(R, T // p)) for p in P]
    sys.stdout.write(" ".join(res))

if __name__ == "__main__":
    main()

This editorial was generated by gpt-5.2-high.

posted:
last update: