forked from keshavnandan/Topcoder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEelAndRabbit.html
30 lines (30 loc) · 4.59 KB
/
EelAndRabbit.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<html><body bgcolor="#000000" text="#ffffff"><table><tr><td colspan="2"><h3>Problem Statement</h3></td></tr><tr><td>    </td><td>Rabbit went to a river to catch eels.
All eels are currently swimming down the stream at the same speed.
Rabbit is standing by the river, downstream from all the eels.
<br></br>
<br></br>
Each point on the river has a coordinate.
The coordinates increase as we go down the stream.
Initially, Rabbit is standing at the origin, and all eels have non-positive coordinates.
<br></br>
<br></br>
You are given two vector <int>s: <b>l</b> and <b>t</b>.
These describe the current configuration of eels.
The speed of each eel is 1 (one).
For each i, the length of eel number i is <b>l</b>[i].
The head of eel number i will arrive at the coordinate 0 precisely at the time <b>t</b>[i].
Therefore, at any time T the eel number i has its head at the coordinate T-<b>t</b>[i], and its tail at the coordinate T-<b>t</b>[i]-<b>l</b>[i].
<br></br>
<br></br>
Rabbit may only catch an eel when some part of the eel (between head and tail, inclusive) is at the same coordinate as the rabbit.
Rabbit can catch eels at most twice.
Each time he decides to catch eels, he may catch as many of the currently available eels as he wants.
(That is, he can only catch eels that are in front of him at that instant, and he is allowed and able to catch multiple eels at once.)
<br></br>
<br></br>
Return the maximal total number of eels Rabbit can catch.</td></tr><tr><td colspan="2"><h3>Definition</h3></td></tr><tr><td>    </td><td><table><tr><td>Class:</td><td>EelAndRabbit</td></tr><tr><td>Method:</td><td>getmax</td></tr><tr><td>Parameters:</td><td>vector <int>, vector <int></td></tr><tr><td>Returns:</td><td>int</td></tr><tr><td>Method signature:</td><td>int getmax(vector <int> l, vector <int> t)</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>64</td></tr></table></td></tr><tr><td colspan="2"><h3>Constraints</h3></td></tr><tr><td align="center" valign="top">-</td><td><b>l</b> will contain between 1 and 50 elements, inclusive.</td></tr><tr><td align="center" valign="top">-</td><td>Each element of <b>l</b> will be between 1 and 1,000,000,000, inclusive.</td></tr><tr><td align="center" valign="top">-</td><td><b>l</b> and <b>t</b> will contain the same number of elements.</td></tr><tr><td align="center" valign="top">-</td><td>Each element of <b>t</b> will be between 0 and 1,000,000,000, inclusive.</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>{2, 4, 3, 2, 2, 1, 10}</pre></td></tr><tr><td><pre>{2, 6, 3, 7, 0, 2, 0}</pre></td></tr></table></td></tr><tr><td><pre>Returns: 6</pre></td></tr><tr><td><table><tr><td colspan="2">Rabbit can catch 6 eels in the following way:
<ul>
<li>At time 2, catch Eel 0, Eel 4, Eel 5, and Eel 6.</li>
<li>At time 8, catch Eel 1 and Eel 3.</li>
</ul>
</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>{1, 1, 1}</pre></td></tr><tr><td><pre>{2, 0, 4}</pre></td></tr></table></td></tr><tr><td><pre>Returns: 2</pre></td></tr><tr><td><table><tr><td colspan="2">No two eels are in front of Rabbit at the same time, so Rabbit can catch at most two eels.</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>{1}</pre></td></tr><tr><td><pre>{1}</pre></td></tr></table></td></tr><tr><td><pre>Returns: 1</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>{8, 2, 1, 10, 8, 6, 3, 1, 2, 5}</pre></td></tr><tr><td><pre>{17, 27, 26, 11, 1, 27, 23, 12, 11, 13}</pre></td></tr></table></td></tr><tr><td><pre>Returns: 7</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>