← All problemsSign in

Distance Sum

CodeChefRating 2399Open on judge ↗

For a given array $A$ of length $N$, we define $f(A)$ in the following way: - Consider a directed graph on $N$ vertices labelled $1$, $2$, $\ldots$, $N$. - There exist a directed edge $i \rightarrow j$ if and only if $i < j \le i + A_i$. - $f(A)$ is defined as the smallest number of edges on a directed path from vertex $1$ to vertex $N$. You are given integers $N$ and $P$, and your task is

HINT LADDERno hints yet
L1 Observation
L2 Technique
L3 Approach
L4 Pseudo-code
🔒
L5 Full solution
L5 unlocks only if you insist twice
solution.cppC++17

CodeSearch Tutor

Hints, not spoilers — it won’t hand over the full solution unless you insist.

voice by Sarvam AI

Sign in to chat with the tutor and save your progress.

Sign in to start