‹ back to the board

Monday, November 2

Adeptalgorithms & data structures

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 trips crossings. Using fewer crossings is fine.

Write minBargeLimit(weights, trips).

  • weights is a list of positive integers: the reliquaries' weights, in quay order. It may be empty.
  • trips is 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.

  • binary search
  • Adept
  • efficiency bonus

examples

  1. case 1weights 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
  2. case 2weights of [1, 1, 100, 1, 1], trips of 2102 — the only two-crossing split is [1, 1, 100] and [1, 1]
  3. case 3weights of [5, 9, 2, 8], trips of 109 — plenty of crossings, but the heaviest reliquary still needs a limit of 9
  4. case 4weights of [], trips of 30
reward
360 XP
signature
minBargeLimit
not yet run

TypeScript, run as ES2022 — types are stripped, not checked. If a JS engine would run it, so will we.

loading the editor…
  • 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
The Reliquary Barge of Lake Senmarrow · bitwick