Algorithm MaxRepeaters(P, n, K)
// Step 1: Calculate station positions
x[1] = 0
for i = 2 to n do
x[i] = x[i - 1] + P[i - 1]
// Step 2: Initialize DP array
DP[0] = 0
// Step 3: Find the maximum number of repeaters
for i = 1 to n do
DP[i] = DP[i - 1] // Skip station i
for j = i - 1 downto 1 do
if x[i] - x[j] >= K then
DP[i] = max(DP[i], DP[j] + 1)
break
DP[i] = max(DP[i], 1)
return DP[n]
Time Complexity: O(n^2)
Space Complexity: O(n)— rhs