C - 荷物の搬入 / Loading the Luggage Editorial by admin Editorial for printing
gpt-5.5-highOverview
Each item must be transported from the warehouse to the rooftop over a distance of \(L\). Since the cost is “the number of items being carried \(\times\) distance”, the minimum cost is simply \(N \times L\).
Observation
The key point of this problem is that the cost is summed up independently for each item.
For example, suppose we move a distance of \(x\) along a certain interval while carrying \(c\) items.
The cost for this movement is
\( c \times x \)
. In other words, a cost of distance \(x\) is incurred for each of the \(c\) items.
Therefore, the total cost can be thought of as:
The sum of the distances each item is transported.
Each item starts at the warehouse at position \(0\) and must eventually reach the rooftop at position \(L\).
Therefore, every item must be transported over a distance of at least \(L\).
Thus, the total cost is at least
\( N \times L \)
.
On the other hand, this lower bound can actually be achieved.
We can simply carry up to \(K\) items at a time and transport them directly from the warehouse to the rooftop.
For example, in the case of \(N = 5, K = 2, L = 10\):
- Transport 2 items directly: cost \(2 \times 10\)
- Transport 2 items directly: cost \(2 \times 10\)
- Transport 1 item directly: cost \(1 \times 10\)
The total is
\( 20 + 20 + 10 = 50 = 5 \times 10 \)
.
Even if we leave items at intermediate landings, the fact that each item must eventually travel a distance of \(L\) does not change, so the cost cannot be made any smaller than this.
Additionally, since the cost of moving empty-handed is \(0\), any need to return to the warehouse after transporting items to the rooftop does not affect the cost.
Algorithm
Read \(N\) and \(L\) from the input, and output
\( N \times L \)
as the answer.
\(K\), the number of landings \(M\), and the positions of each landing \(D_i\) do not affect the answer.
Complexity
- Time Complexity: \(O(1)\)
- Space Complexity: \(O(1)\)
Implementation Notes
Since \(N\) and \(L\) can be up to \(10^9\), the answer \(N \times L\) can be up to \(10^{18}\).
In Python, there is no need to worry about integer overflow.
When implementing in languages like C++, you must use a 64-bit integer type such as long long.
Source Code
import sys
N, K, M, L = map(int, sys.stdin.buffer.readline().split())
print(N * L)
This editorial was generated by gpt-5.5-high.
posted:
last update: