The Reliquary Barge of Lake Senmarrow
The drowned chapels on the far shore of Lake Senmarrow are to be resealed, and the Wardens of Senmarrow need their sacred reliquaries carried across. The Wardens have commissioned the barge and want it built light. A barge rated for more weight costs more to build. The guild must therefore name the lowest weight rating that still gets the job done.
The reliquaries stand on the quay in a fixed row, and the rules of the crossing are strict:
- The reliquaries must be loaded in the order they stand. Each crossing carries a contiguous run of the next reliquaries still on the quay.
- A reliquary is never split between crossings.
- The total weight carried on one crossing must not exceed the barge's limit. Exactly equal to the limit is allowed.
- All reliquaries must be across in at most
tripscrossings. Using fewer crossings is fine.
Write minBargeLimit(weights, trips).
weightsis a list of positive integers: the reliquaries' weights, in quay order. It may be empty.tripsis a positive integer (at least 1): the most crossings allowed.
Return the smallest integer weight limit under which every reliquary can be carried across within trips crossings. If weights is empty, return 0.
examples
- case 1
weights of [3, 2, 2, 4, 1, 4], trips of 36 — crossings [3, 2], [2, 4], [1, 4]; a limit of 5 would need 4 crossings - case 2
weights of [1, 1, 100, 1, 1], trips of 2102 — the only two-crossing split is [1, 1, 100] and [1, 1] - case 3
weights of [5, 9, 2, 8], trips of 109 — plenty of crossings, but the heaviest reliquary still needs a limit of 9 - case 4
weights of [], trips of 30
- reward
- 360 XP
- signature
minBargeLimit
TypeScript, run as ES2022 — types are stripped, not checked. If a JS engine would run it, so will we.
- classic six reliquaries in three crossings
- ten ascending weights in five crossings
- four crossings for five reliquaries
- heavy reliquary in the middle
- uneven split in two crossings
- more crossings than reliquaries
- single crossing carries everything
- single reliquary
- empty quay
- forty heavy reliquaries in four crossings
- fifty reliquaries in five crossings