forked from keshavnandan/Topcoder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathICPCBalloons.html
16 lines (16 loc) · 7.79 KB
/
ICPCBalloons.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<html><body bgcolor="#000000" text="#ffffff"><table><tr><td colspan="2"><h3>Problem Statement</h3></td></tr><tr><td>    </td><td>You are organizing a subregional ACM ICPC contest. The problemset at the contest will consist of M problems. According to an ACM ICPC tradition, when a team solves a problem, it gets awarded a balloon. To account for this, you've bought balloons of N different colors (conveniently numbered from 0 to N-1). The number of balloons of color i that you've bought is given by <b>balloonCount</b>[i]. Balloons come in two sizes: medium and large. All balloons of the same color have the same size. If the i-th character of <b>balloonSize</b> is 'M', then all balloons of color i have medium size, and if this character is 'L', then all balloons of color i have large size.
<br></br><br></br>
Today you've been at the meeting with the scientific committee of the contest. There, you learned that there are additional restrictions of which you were not aware. Here are those restrictions:
<ul>
<li>All balloons that get awarded for a particular problem must have the same color and size.</li>
<li>For any two problems, the colors of balloons awarded for solving them must be different. In other words, the color of balloons awarded for each problem must be unique.</li>
</ul>
These are definitely bad news, since you ordered balloons pretty much arbitrarily and it's possible that you won't be able to satisfy the restrictions with the balloons you currently have. However, the good news is that scientific committee members were able to evaluate the difficulty of each problem. More exactly, they told you that the maximum number of teams that can potentially solve the i-th problem is <b>maxAccepted</b>[i]. The scientific committee members are very clever and experienced, so their prediction is guaranteed to come true.
<br></br><br></br>
Your budget is limited and balloons are expensive, so buying more of them is not an option. Fortunately, there is a very cheap balloon repaint service at your city, so you are going to use it. The service offers repainting a given balloon into any other color. This can be one of the N colors you have, as well as any color that you don't have yet. However, it is not possible to change the size of a balloon.
<br></br><br></br>
You are given the vector <int>s <b>balloonCount</b>, <b>maxAccepted</b> and the string <b>balloonSize</b>. Return the minimum number of balloons that have to be repainted in order to guarantee that you will be able to award balloons to the teams properly. If it is impossible to achieve the goal using any number of balloon repaintings, return -1.</td></tr><tr><td colspan="2"><h3>Definition</h3></td></tr><tr><td>    </td><td><table><tr><td>Class:</td><td>ICPCBalloons</td></tr><tr><td>Method:</td><td>minRepaintings</td></tr><tr><td>Parameters:</td><td>vector <int>, string, vector <int></td></tr><tr><td>Returns:</td><td>int</td></tr><tr><td>Method signature:</td><td>int minRepaintings(vector <int> balloonCount, string balloonSize, vector <int> maxAccepted)</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>balloonCount</b> will contain between 1 and 50 elements, inclusive.</td></tr><tr><td align="center" valign="top">-</td><td>Each element of <b>balloonCount</b> will be between 1 and 100, inclusive.</td></tr><tr><td align="center" valign="top">-</td><td><b>balloonSize</b> will contain the same number of characters as the number of elements in <b>balloonCount</b>.</td></tr><tr><td align="center" valign="top">-</td><td>Each character of <b>balloonSize</b> will be 'M' or 'L'.</td></tr><tr><td align="center" valign="top">-</td><td><b>maxAccepted</b> will contain between 1 and 15 elements, inclusive.</td></tr><tr><td align="center" valign="top">-</td><td>Each element of <b>maxAccepted</b> will be between 1 and 100, 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>{100}</pre></td></tr><tr><td><pre>"L"</pre></td></tr><tr><td><pre>{1,2,3,4,5}</pre></td></tr></table></td></tr><tr><td><pre>Returns: 10</pre></td></tr><tr><td><table><tr><td colspan="2">You have 100 large balloons of the same color. 5 of them can be used for problem 4 and 1+2+3+4=10 balloons need to be repainted in order to be used for remaining problems.</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>{100}</pre></td></tr><tr><td><pre>"M"</pre></td></tr><tr><td><pre>{10,20,30,40,50}</pre></td></tr></table></td></tr><tr><td><pre>Returns: -1</pre></td></tr><tr><td><table><tr><td colspan="2">We don't have enough balloons. Repainting is not going to help.</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>{5,6,1,5,6,1,5,6,1}</pre></td></tr><tr><td><pre>"MLMMLMMLM"</pre></td></tr><tr><td><pre>{7,7,4,4,7,7}</pre></td></tr></table></td></tr><tr><td><pre>Returns: 6</pre></td></tr><tr><td><table><tr><td colspan="2">(Note that all of the indices in this annotation are 0-based.)
<br></br><br></br>
Repaint one balloon of color 7 into color 1. Repaint one balloon of color 7 into color 4. Now large balloons can be awarded for problems 0, 1, and 2.
<br></br><br></br>
Repaint two balloons of colors 2 and 5 into color 0. Repaint two balloons of colors 6 and 8 into color 3. Now medium balloons of colors 0, 3, and 6 can be awarded for problems 3, 4, and 5.</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>{100,100}</pre></td></tr><tr><td><pre>"ML"</pre></td></tr><tr><td><pre>{50,51,51}</pre></td></tr></table></td></tr><tr><td><pre>Returns: -1</pre></td></tr><tr><td><table><tr><td colspan="2">Even though we have 200 balloons overall and only at most 152 accepted solutions, there is still no way of dividing and repainting the balloons that works.</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>{8,5,1,4,1,1,3,1,3,3,5,4,5,6,9}</pre></td></tr><tr><td><pre>"MMMLLLMMLLMLMLM"</pre></td></tr><tr><td><pre>{3,5,3,3,5,6,4,6,4,2,3,7,1,5,2}</pre></td></tr></table></td></tr><tr><td><pre>Returns: 5</pre></td></tr><tr><td><table><tr><td colspan="2"></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>{1,18,4,7,19,7,7,1,4,8,10,5,14,13,8,22,6,3,13,5,3,4,2,1,3,15,19,4,5,9,4,11,2,7,12,20,11,26,22,7,2,10,9,20,13,20,2,9,11,9}</pre></td></tr><tr><td><pre>"LLMLLLLMLLLLLLLLLLLLMLLLLLLLLLLMMLMLLLMLLLLLLLLMLL"</pre></td></tr><tr><td><pre>{44,59,29,53,16,23,13,14,29,42,13,15,66,4,47}</pre></td></tr></table></td></tr><tr><td><pre>Returns: 210</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>