You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<p><em>Single Round Match 587 Round 1 - Division I, Level One</em></p>
9
+
10
+
<h2>Statement</h2>
11
+
12
+
<p>Little Fox Jiro is standing at the bottom of a long flight of stairs.
13
+
The bottom of the stairs has number 0, the bottommost step has number 1, the next step has number 2, and so on.
14
+
The staircase is so long that Jiro is guaranteed not to reach its top.</p>
15
+
16
+
<p>Jiro will now perform <em>N</em> consecutive actions.
17
+
The actions are numbered 1 through <em>N</em>, in order.
18
+
When performing action X, Jiro chooses between two options: either he does nothing, or he jumps exactly X steps up the stairs.
19
+
In other words, if Jiro starts performing action X standing on step Y, he will end it either on step Y, or on step Y+X.</p>
20
+
21
+
<p>For example, if <em>N</em>=3, Jiro will make three consecutive choices: whether or not to jump 1 step upwards, 2 steps upwards, and then 3 steps upwards.</p>
22
+
23
+
<p>One of the steps is broken.
24
+
The number of this step is <em>badStep</em>.
25
+
Jiro cannot jump onto this step.</p>
26
+
27
+
<p>You are given the ints <em>N</em> and <em>badStep</em>.
28
+
Compute and return the number of the topmost step that can be reached by Jiro.</p>
<li><em>Method signature</em>: <code>int furthest(int N, int badStep)</code></li>
38
+
</ul>
39
+
40
+
41
+
<h2>Constraints</h2>
42
+
43
+
<ul>
44
+
<li><em>N</em> will be between 1 and 2,000, inclusive.</li>
45
+
<li><em>badStep</em> will be between 1 and 4,000,000, inclusive.</li>
46
+
</ul>
47
+
48
+
49
+
<h2>Examples</h2>
50
+
51
+
<h3>Example 1</h3>
52
+
53
+
<h4>Input</h4>
54
+
55
+
<p><c>2,<br/>2</c></p>
56
+
57
+
<h4>Output</h4>
58
+
59
+
<p><c>3</c></p>
60
+
61
+
<h4>Reason</h4>
62
+
63
+
<p>The optimal strategy is to jump upwards twice: from step 0 to step 1, and then from step 1 to step 3. This trajectory avoids the broken step.</p>
64
+
65
+
<h3>Example 2</h3>
66
+
67
+
<h4>Input</h4>
68
+
69
+
<p><c>2,<br/>1</c></p>
70
+
71
+
<h4>Output</h4>
72
+
73
+
<p><c>2</c></p>
74
+
75
+
<h4>Reason</h4>
76
+
77
+
<p>In this case step 1 is broken, so Jiro cannot jump upwards as his first action. The optimal strategy is to first stay on step 0, and then to jump from step 0 to step 2.</p>
0 commit comments