forked from daiwb/Algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAlbertoTheAviator.html
More file actions
18 lines (15 loc) · 5.49 KB
/
Copy pathAlbertoTheAviator.html
File metadata and controls
18 lines (15 loc) · 5.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<html><body bgcolor="#000000" text="#ffffff"><table><tr><td colspan="2"><h3>Problem Statement</h3></td></tr><tr><td>    </td><td><p>Alberto is an aviation pioneer.
He pilots an airplane called "14-bis".
Initially, there are <b>F</b> units of fuel in the fuel tank of his airplane.</p><br></br><br></br>
<p>There are some flight missions Alberto may take.
The missions all start and end in the same location, and he may do them in any order.
However, he can only do each mission at most once.
You are given two vector <int>s of the same length: <b>duration</b> and <b>refuel</b>.
For each valid i:<br></br><br></br>
<ul>
<li><b>duration</b>[i] is the amount of fuel consumed while running mission i</li>
<li>After Alberto completes mission i and gets paid, he will buy <b>refuel</b>[i] units of fuel. This amount will always be strictly smaller than the amount consumed during the mission.</li>
</ul></p><br></br>
<p>Alberto can only choose a mission if he has enough fuel for it.
That is, at the beginning of the mission his fuel tank must have at least <b>duration</b>[i] units of fuel.</p><br></br><br></br>
<p>Compute and return the maximum number of missions Alberto can take.</p></td></tr><tr><td colspan="2"><h3>Definition</h3></td></tr><tr><td>    </td><td><table><tr><td>Class:</td><td>AlbertoTheAviator</td></tr><tr><td>Method:</td><td>MaximumFlights</td></tr><tr><td>Parameters:</td><td>int, vector <int>, vector <int></td></tr><tr><td>Returns:</td><td>int</td></tr><tr><td>Method signature:</td><td>int MaximumFlights(int F, vector <int> duration, vector <int> refuel)</td></tr><tr><td colspan="2">(be sure your method is public)</td></tr></table></td></tr><tr><td colspan="2"><h3>Limits</h3></td></tr><tr><td>    </td><td><table><tr><td>Time limit (s):</td><td>2.000</td></tr><tr><td>Memory limit (MB):</td><td>256</td></tr></table></td></tr><tr><td colspan="2"><h3>Constraints</h3></td></tr><tr><td align="center" valign="top">-</td><td><b>F</b> will be between 1 and 5,000 inclusive.</td></tr><tr><td align="center" valign="top">-</td><td><b>duration</b> and <b>refuel</b> will have between 1 and 50 elements, inclusive.</td></tr><tr><td align="center" valign="top">-</td><td>Each element of <b>duration</b> will be between 1 and 5,000, inclusive.</td></tr><tr><td align="center" valign="top">-</td><td>Each element of <b>refuel</b> will be between 0 and 5,000, inclusive.</td></tr><tr><td align="center" valign="top">-</td><td>For each i, <b>refuel</b>[i] will be strictly smaller than <b>duration</b>[i].</td></tr><tr><td align="center" valign="top">-</td><td><b>duration</b> and <b>refuel</b> will contain the same number of elements.</td></tr><tr><td colspan="2"><h3>Examples</h3></td></tr><tr><td align="center" nowrap="true">0)</td><td></td></tr><tr><td>    </td><td><table><tr><td><table><tr><td><pre>10</pre></td></tr><tr><td><pre>{10}</pre></td></tr><tr><td><pre>{0}</pre></td></tr></table></td></tr><tr><td><pre>Returns: 1</pre></td></tr><tr><td><table><tr><td colspan="2">There is only one mission. Alberto has enough fuel to take it, so the optimal solution is to take it.</td></tr></table></td></tr></table></td></tr><tr><td align="center" nowrap="true">1)</td><td></td></tr><tr><td>    </td><td><table><tr><td><table><tr><td><pre>10</pre></td></tr><tr><td><pre>{8, 4}</pre></td></tr><tr><td><pre>{0, 2}</pre></td></tr></table></td></tr><tr><td><pre>Returns: 2</pre></td></tr><tr><td><table><tr><td colspan="2"></td></tr></table></td></tr></table></td></tr><tr><td align="center" nowrap="true">2)</td><td></td></tr><tr><td>    </td><td><table><tr><td><table><tr><td><pre>12</pre></td></tr><tr><td><pre>{4, 8, 2, 1}</pre></td></tr><tr><td><pre>{2, 0, 0, 0}</pre></td></tr></table></td></tr><tr><td><pre>Returns: 3</pre></td></tr><tr><td><table><tr><td colspan="2"></td></tr></table></td></tr></table></td></tr><tr><td align="center" nowrap="true">3)</td><td></td></tr><tr><td>    </td><td><table><tr><td><table><tr><td><pre>9</pre></td></tr><tr><td><pre>{4, 6}</pre></td></tr><tr><td><pre>{0, 1}</pre></td></tr></table></td></tr><tr><td><pre>Returns: 2</pre></td></tr><tr><td><table><tr><td colspan="2"></td></tr></table></td></tr></table></td></tr><tr><td align="center" nowrap="true">4)</td><td></td></tr><tr><td>    </td><td><table><tr><td><table><tr><td><pre>100</pre></td></tr><tr><td><pre>{101}</pre></td></tr><tr><td><pre>{100}</pre></td></tr></table></td></tr><tr><td><pre>Returns: 0</pre></td></tr><tr><td><table><tr><td colspan="2">There is only one mission. Alberto does not have enough fuel to take it. The answer is 0.</td></tr></table></td></tr></table></td></tr><tr><td align="center" nowrap="true">5)</td><td></td></tr><tr><td>    </td><td><table><tr><td><table><tr><td><pre>1947</pre></td></tr><tr><td><pre>{2407, 2979, 1269, 2401, 3227, 2230, 3991, 2133, 3338, 356, 2535, 3859, 3267, 365}</pre></td></tr><tr><td><pre>{2406, 793, 905, 2400, 1789, 2229, 1378, 2132, 1815, 355, 72, 3858, 3266, 364}</pre></td></tr></table></td></tr><tr><td><pre>Returns: 3</pre></td></tr><tr><td><table><tr><td colspan="2"></td></tr></table></td></tr></table></td></tr></table><p>This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved. </p></body></html>