Official

C - 荷物の搬入 / Loading the Luggage Editorial by admin Editorial for printing

gpt-5.5-high

Summary

All items must be carried from the warehouse to the rooftop, a distance of \(L\).
Since the transportation cost is “number of items being carried \(\times\) distance”, the minimum cost is simply \(N \times L\).

Analysis

The key to this problem is to look at each item individually.

Each item is initially in the warehouse, which is at distance \(0\).
Eventually, it must reach the rooftop, which is at distance \(L\).

Therefore, no matter what path is taken, each item must be carried for a total distance of at least \(L\).

Carrying \(1\) item for a distance of \(1\) costs \(1\).
Thus, a minimum cost of \(L\) is required for each item.

Since there are \(N\) items in total, the overall cost is at least

\(N \times L\)

On the other hand, this cost is indeed achievable.

For example, you can simply carry the items directly from the warehouse to the rooftop in batches of at most \(K\) items.
There is no need to use any of the landings along the way.

Carrying \(x\) items at a time costs

\(x \times L\)

Since the sum of the number of items carried across all trips is \(N\), the total cost is

\(N \times L\)

Furthermore, the cost of returning empty-handed is \(0\), so making multiple round trips does not incur any additional cost.

Therefore, regardless of the positions or number of the landings, or the value of \(K\), the answer is always

\(N \times L\)

There is no need to naively consider things like “on which landing to place the items” or “how many items to carry at a time”. Simulating such processes might not run within the time limit because \(N\) and \(K\) can be as large as \(10^9\).

Algorithm

Read \(N, K, M, L\) from the input.

Since the answer is always

\(N \times L\)

simply output that value.

The distances of the landings \(D_i\) do not affect the answer, so you do not even need to read them.

Complexity

  • Time Complexity: \(O(1)\)
  • Space Complexity: \(O(1)\)

Implementation Points

Since \(N\) and \(L\) can be up to \(10^9\), their product \(N \times L\) can be up to \(10^{18}\).

This does not fit in a 32-bit signed integer, so we should use long long in C++.

long long N, K, M, L;
cin >> N >> K >> M >> L;

cout << N * L << '\n';

Source Code

#include <bits/stdc++.h>
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    long long N, K, M, L;
    cin >> N >> K >> M >> L;

    cout << N * L << '\n';
    return 0;
}

This editorial was generated by gpt-5.5-high.

posted:
last update: