Mutalisk
SRM 658 · 2015-05-01 · by cgy4ever
Problem Statement
In Starcraft, one of the available units is a mutalisk. Mutalisks are very useful for harassing Terran bases. Fox Ciel has one mutalisk. The enemy base contains one or more Space Construction Vehicles (SCVs). Each SCV has some amount of hit points.
When the mutalisk attacks, it can target up to three different SCVs.
- The first targeted SCV will lose 9 hit points.
- The second targeted SCV (if any) will lose 3 hit points.
- The third targeted SCV (if any) will lose 1 hit point.
You are given a
Constraints
- x will contain between 1 and 20 elements, inclusive.
- Each element in x will be between 1 and 60, inclusive.
Statement by TopCoder, Inc. — view the original on the archive.
{12,10,4}
Returns: 2
You can destroy all SCVs in two attacks as follows: Target the SCVs in the order 0, 2, 1. Their hit points after the attack will be {12-9, 10-1, 4-3} = {3, 9, 1}. Target the SCVs in the order 1, 0, 2. Their hit points will drop exactly to {0, 0, 0}.
{54,18,6}
Returns: 6
You should attack 6 times, always in the order 0, 1, 2.
{1,1,1,1,1,1,1,1,1,1}
Returns: 4
There are 10 SCVs, each with just a single hit point. Your attack can kill only three of them, therefore at least 4 attacks are needed.
{55,60,53}
Returns: 13
{60}
Returns: 7
Submissions are judged against all 107 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class Mutalisk with a public method int minimalAttacks(vector<int> x) · 107 test cases · 2 s / 256 MB per case