IBMOA #46
Max Index
Estimated MediumJudge-ready
Topics (AI-labelled)Bits & MathGreedy
You start at index 0. At step j you may move forward j cells or stay in place, for steps steps in total, and you must never stop at badIndex at any moment. Find the maximum final index. If the starting point itself is forbidden, there is no valid path, and this site outputs -1.
Input
One line containing steps badIndex. Original bound: 1≤steps≤2000; the original bound on badIndex is missing, and on this site 0≤badIndex≤10^9.
Output
Output one integer, the answer.
Example 1
Input:
4 6
Output:
9
Example 2
Input:
3 4
Output:
6
Example 3
Input:
2 0
Output:
-1
Example notes
The examples give 9, 6 and -1 respectively.
Editorial
Loading solution…