Unpacking
SRM 726 · 2017-12-18 · by subscriber
Problem Statement
Constraints
- a, b and cost will contain the same number of elements.
- a will contain between 1 and 50 elements, inclusive.
- Each element in a, b and cost will be between 1 and 10,000, inclusive.
- K will be between 1 and 10,000, inclusive.
{6,5}
{4,4}
{1,1}
10
Returns: 2
There are two boxes, each with cost 1. One box promises to hold 6 red + 4 blue candies, the other promises to hold 5 red + 4 blue ones. Hero will be happy if he opens 10 candies of the same color. Clearly, buying just one box is not enough. Is Hero guaranteed to be happy if he buys both of them? As it turns out, yes. In most cases, he will open at least 10 red candies and he will be happy. The only case in which that won't happen is the case when the first box actually contains 5 red + 5 blue and the second box contains 4 red + 5 blue candies. However, in this case Hero will also be happy, because he will open 10 blue candies.
{5,5}
{4,4}
{1,1}
10
Returns: -1
Even if Hero buys both boxes, it is possible that he will only open 9 red + 9 blue candies in total.
{10}
{5}
{13}
9
Returns: 13
{1,2,3,4,5}
{1,2,3,4,5}
{1,2,3,4,5}
10
Returns: 10
{1,2,3,4,15}
{1,2,3,4,5}
{1,2,3,4,5}
17
Returns: 9
Submissions are judged against all 127 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class Unpacking with a public method int getcost(vector<int> a, vector<int> b, vector<int> cost, int K) · 127 test cases · 2 s / 256 MB per case