Description:
In the previous problems, you were given a target T and asked to find the minimum number of steps to reach it. In this final challenge, the target T is no longer given. Instead, you must identify the most difficult target.
Given a vector of jug capacities C, every reachable amount T ( where 1 <= T <= max(C) ) has a shortest path ( minimum steps ) required to measure it in at least one jug. Your task is to find the value of T that requires the highest number of minimum steps.
Definition:
Let f(T) be the minimum number of operations required to obtain exactly T units in any jug.
Find T* such that f(T) is the maximized for reachable T belongs to {1, 2, ... max( C ) }.
Example:
  • Input: [3,5]
  • Possible targets T and their minimum steps f(T)
  • f(3) = 1 step ( Fill 3 )
  • f(5) = 1 step ( Fill 5 )
  • f(2) = 2 steps ( Fill 5 -> Pour 5 to 3 )
  • f(1) = 4 steps ( Fill 3 -> Pour 3 to 5 -> Fill 3 -> Pour 3 to 5 )
  • f(4) = 6 steps ( Fill 5 -> Pour 5 to 3 -> Empty 3 -> Pour 5 to 3 -> Fill 5 -> Pour 5 to 3 )
  • The maximum of these minimum is 6 steps, which occurs when T = 4
  • Output: 4

Solution Stats

16 Solutions

11 Solvers

Last Solution submitted on May 24, 2026

Last 200 Solutions

Problem Comments

Solution Comments

Show comments
Loading...