A - 配送トラックの選択 / Selection of Delivery Trucks Editorial by admin
Qwen3-Coder-480BOverview
This problem asks you to select one truck from \(N\) trucks and minimize the total fuel consumed when visiting \(M\) delivery destinations in order.
Analysis
Each truck \(i\) has a fuel efficiency coefficient \(E_i\), and given the distance \(C_j\) to delivery destination \(j\), the fuel consumed when truck \(i\) travels to destination \(j\) is \(E_i \times C_j\).
Since all delivery destinations must be visited, the total distance traveled is the same regardless of which truck is chosen: $\( \sum_{j=1}^{M} C_j \)\( In other words, **the total distance is the same for any truck**, so **choosing the truck with the smallest fuel efficiency coefficient \)E_i$ is optimal**.
Therefore, rather than computing total distance × fuel efficiency coefficient for every truck and comparing them, we simply find the minimum fuel efficiency coefficient and multiply it by the total distance.
This approach avoids unnecessary repeated calculations and allows us to find the answer efficiently.
Algorithm
Compute the sum of distances to each delivery destination \(C_1, C_2, ..., C_M\): $\( \text{total\_distance} = \sum_{j=1}^{M} C_j \)$
Find the minimum value among the fuel efficiency coefficients \(E_1, E_2, ..., E_N\) of all trucks: $\( \text{min\_E} = \min(E_1, E_2, ..., E_N) \)$
The minimum fuel consumption is computed as follows: $\( \text{result} = \text{min\_E} \times \text{total\_distance} \)$
Output this result.
Complexity
- Time complexity: \(O(N + M)\) (since we scan each list exactly once)
- Space complexity: \(O(1)\) (excluding input data, only a constant number of variables are used)
Implementation Notes
By computing the total distance and the minimum fuel efficiency coefficient separately, we can calculate the answer efficiently.
In Python, this can be implemented concisely using
sum()andmin().Source Code
# 入力の読み込み
N, M = map(int, input().split())
E = list(map(int, input().split()))
C = list(map(int, input().split()))
# 総距離を計算
total_distance = sum(C)
# 最小の燃費係数を求める
min_E = min(E)
# 最小燃料消費量を計算
result = min_E * total_distance
# 出力
print(result)
This editorial was generated by qwen3-coder-480b.
posted:
last update: