MarbleTop
TCCC07 Round 1B · 2007-07-30 · by dgoodman
Problem Statement
int[] stock contains the lengths of marble that we have on hand, andint[] orders contains the lengths that our customers have ordered. Given k, stock, and orders, return the minimum number of cuts needed to satisfy all our customers. If it is not possible, return -1.
Constraints
- k will be between 1 and 40, inclusive.
- stock and orders will each contain between 1 and 50 elements, inclusive.
- Each element of stock and of orders will be between 1 and 40, inclusive.
5
{5,3,11}
{10,3,5}
Returns: -1
There is no way to deliver a piece of length 10. The only sizes we could deliver are 11,6,5,3,1.
5
{5,3,11}
{6,6,5}
Returns: -1
We can deliver one length of 6 and a length of 5 but not the second 6.
1
{7,6,2,1}
{3,1,1,1,1,1,1}
Returns: 4
Cut the 6 into a 5 and 1, cut the 5 into a 4 and 1, cut the 4 into a 3 and 1. Now we have 7, 3, 2, and four 1's. Cut the 2 and we have (in addition to the 7) a 3 and 6 1's as needed.
6
{4}
{20,5,11}
Returns: -1
6
{8,16,6,37,11,21}
{4,6,6,6}
Returns: 2
Submissions are judged against all 53 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class MarbleTop with a public method int minCuts(int k, vector<int> stock, vector<int> orders) · 53 test cases · 2 s / 256 MB per case