values. Pick a non-empty subsequence at indices i₀ < i₁ < … < iₘ₋₁. It is steep if each picked element exceeds the previous one by at least the distance between them:
values[iⱼ] - values[iⱼ₋₁] ≥ iⱼ - iⱼ₋₁ for every j from 1 to m - 1.
A single element is always steep. Return the largest possible sum of a steep subsequence.values=[1, 4, 2, 8] → 13
Take indices 0, 1, 3: 4 - 1 ≥ 1 - 0 and 8 - 4 ≥ 3 - 1. The sum is 1 + 4 + 8 = 13.
values=[-5, -2, -9] → -2
All numbers are negative, so the best choice is the single number -2.
values=[3, 2, 1, 7] → 10
3 and 7 differ by 4 at distance 3, which is fine, giving 10. Pairs like 3, 2 or 2, 1 do not qualify.
values=[1, 4, 2, 8]
13
Run checks the first 3 tests in your browser. Submit checks all 159 tests on the server, hidden ones included.