Datasets:

Modalities:
Image
Text
Formats:
parquet
Size:
< 1K
Tags:
code
Libraries:
Datasets
pandas
License:
hackercup / 2018 /round3 /finshakes.html
wjomlex's picture
2018 Problems
ab396f0 verified
raw
history blame
3.64 kB
<p>
You know what a finshake is, right? It's just like a handshake. Except performed by fish rather than humans.
</p>
<p>
There are <strong>N</strong> pools of water in a row, numbered from 1 to <strong>N</strong> in order.
Pool <em>i</em>'s water level is at an elevation of <strong>H<sub>i</sub></strong> metres. There are <strong>N</strong> - 1 equally-tall walls, one between each pair of adjacent pools,
with the top of each wall at an elevation of <strong>W</strong> metres.
All of the water levels are lower than the tops of the walls (in other words, <strong>H<sub>i</sub></strong> &lt; <strong>W</strong> for each <em>i</em>).
</p>
<p>
There are also <strong>M</strong> fish throughout the pools. The <em>i</em>th fish initially lives in pool <strong>P<sub>i</sub></strong>,
and has a jumping height of <strong>J<sub>i</sub></strong> metres. It can jump over a wall from any given pool <strong>a</strong> to an adjacent pool <strong>b</strong>
(such that |<strong>a</strong> - <strong>b</strong>| = 1) if and only if <strong>J<sub>i</sub></strong> &gt; <strong>W</strong> - <strong>H<sub>a</sub></strong>.
Multiple fish may live in the same pool.
</p>
<p>
Each of the <strong>M</strong> fish will spend some time jumping over walls amongst the pools, before each choosing a final pool to settle in.
After all of the fish have settled down, for each unique unordered pair of fish who have ended up in the same pool as one another, they will give each other a finshake.
Assuming the fish all work together, what's the maximum number of finshakes which can occur once they've all settled down in their chosen pools?
</p>
<h3>Input</h3>
<p>
Input begins with an integer <strong>T</strong>, the number of rows of pools.
For each row of pools, there is first a line containing the space-separated integers <strong>N</strong>, <strong>M</strong>, and <strong>W</strong>.
Then follows a line containing the <strong>N</strong> space-separated integers <strong>H<sub>1</sub></strong> through <strong>H<sub>N</sub></strong>.
Then <strong>M</strong> lines follow, the <em>i</em>th of which contains the space-separated integers <strong>P<sub>i</sub></strong> and <strong>J<sub>i</sub></strong>.
</p>
<h3>Output</h3>
<p>
For the <em>i</em>th row of pools, output a line containing "Case #<em>i</em>: " followed by the maximum number of finshakes which can occur.
</p>
<h3>Constraints</h3>
<p>
1 &le; <strong>T</strong> &le; 50 <br />
1 &le; <strong>N</strong> &le; 500 <br />
1 &le; <strong>M</strong> &le; 50 <br />
2 &le; <strong>W</strong> &le; 1,000,000 <br />
1 &le; <strong>H<sub>i</sub></strong> &lt; <strong>W</strong> <br />
1 &le; <strong>P<sub>i</sub></strong> &le; <strong>N</strong> <br />
1 &le; <strong>J<sub>i</sub></strong> &le; 1,000,000 <br />
</p>
<h3>Explanation of Sample</h3>
<p>
In the first case, neither fish has a sufficient jumping height to jump over the wall from its own pool to the other pool.
As such, each fish must remain isolated in its own pool, resulting in 0 finshakes being exchanged.
</p>
<p>
In the second case, the second fish has sufficient jumping strength to go back and forth over the wall. It should choose to settle in the first pool.
With both fish ending up in the same pool, they'll exchange 1 finshake.
</p>
<p>
In the third case, the first fish is unable to leave the first pool. The fourth fish could decide to choose to stay in the first pool as well, and give the first fish a finshake.
However, it's better for the last 3 fish to all congregate in the second pool instead, as this will result in a total of 3 finshakes being exchanged amongst them.
</p>