cswork / OA打开练习工作台

IBMOA #46

Max Index

估计中等可在线判题

考点(AI 标注)位运算贪心调度

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.

输入格式

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 one integer, the answer.

样例 1

输入:

4 6

输出:

9

样例 2

输入:

3 4

输出:

6

样例 3

输入:

2 0

输出:

-1

样例说明

The examples give 9, 6 and -1 respectively.