Nile
Time limit2sMemory limit1024 MB
For each query D, find the minimum cost to ship all artifacts when two artifacts share a boat only if their weights differ by at most D.
- Level
Hard8 of 10
- Topics
- Dynamic programming, Sorting, Segment tree
- Solved
- No attempts yet
Problem
You want to transport artifacts through the Nile. The artifacts are numbered from to . The weight of artifact () is .
You use specialized boats to transport the artifacts. Each boat can carry at most two artifacts.
- If you put a single artifact in a boat, its weight can be arbitrary.
- If you put two artifacts in the same boat, the boat must be balanced. Specifically, artifacts and () can share a boat only when their weights differ by at most , that is, .
The cost of transporting artifact () depends on how many artifacts share its boat:
- , if the artifact rides in its own boat.
- , if the artifact shares a boat with another artifact.
In the second case, you pay for both artifacts in the boat. If artifacts and () share a boat, you pay .
A boat with a single artifact always costs more than sharing, so for every ().
The river conditions are hard to predict, so the value of changes often. Answer questions numbered from to . The questions are given as an array of length . The answer to question () is the minimum total cost of transporting all artifacts when equals .
Constraints
- for every ()
- for every ()
- for every ()