DOJ logoDOJ
Problems
Recently added problemsSaved problems
CategoriesDLCContestsGroupsTeamsBoard
Ranking
Solved Problem RankingStreak rankingDOJ Power ranking
Status
Call for TasksLoginRegister
DOJ logoDOJ

Community online judge with OI-style subtask scoring, Elo ratings, and Discord-backed certification.

Problems
ProblemsCategories
Community
ContestsRankingBoardNoticesHost an external contestGuide
Account
LoginRegisterJudge Status
Policy
Terms of ServiceDLC RulesPrivacyAPI documentationLanguage runtimesContest rank rewardsRating and performance
© 2026 DOJ
All rights reserved
Editorial

Moving

Back to problem

Editorial

Let eee be the right endpoint reachable with the current number of moves, and let fff be the farthest position reachable with one additional move from this range.

Scan positions from left to right and update f=max⁡(f,i+Ai)f=\max(f,i+A_i)f=max(f,i+Ai​). When i=ei=ei=e, the computed fff becomes the endpoint for the next move count. If the range no longer expands, position NNN is unreachable.

The time complexity is O(N)O(N)O(N) per test case.

Solution written by GPT5