DivideLoot
SRM 795 · 2020-12-11 · by misof
Problem Statement
N pirates have stolen a treasure chest.
The treasure chest contains some loot.
The prices of the individual items in the chest are given in the
The pirates want to divide the loot according to the following rules:
- Each pirate must get at least one item.
- Each pirate must get at most two items.
- Each pirate must get items with the same total price.
Return "possible" if the pirates can divide the loot according to the above rules, or "impossible" if they cannot do that.
Notes
- Note that the return value is case-sensitive.
- Each item must be assigned to one of the pirates. It is not allowed to leave items without an owner.
Constraints
- N will be between 1 and 50, inclusive.
- loot will contain between N and 2N-1 elements, inclusive.
- Each element of loot will be between 1 and 1000, inclusive.
1
{47}
Returns: "possible"
The only pirate gets the only item.
3
{10, 8, 10, 1, 1}
Returns: "impossible"
We cannot divide these items according to the rules. The only way in which each pirate gets the same total value requires one pirate getting three items (8+1+1) which is not allowed.
3
{3, 9, 10, 7, 1}
Returns: "possible"
One pirate gets 3+7, one gets 9+1, and one gets 10.
6
{1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1}
Returns: "possible"
2
{40, 1, 42}
Returns: "impossible"
Submissions are judged against all 119 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class DivideLoot with a public method string verify(int N, vector<int> loot) · 119 test cases · 2 s / 256 MB per case