Cody

Problem 44787. What can you get for exactly amount of money(harder)

Solution 1986910

Submitted on 23 Oct 2019 by Sean Kavanagh
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

Test Suite

Test Status Code Input and Output
1   Pass
v = [ 195 125 260 440 395 290]; s = 570; tic res = buy(v, s); toc assert(sum(res) == s); assert(all(ismember(res, v)))

Elapsed time is 0.042894 seconds.

2   Pass
v = [ 150 180 60 40]; s = 210; tic res = buy(v, s); toc assert(sum(res) == s); assert(all(ismember(res, v)))

Elapsed time is 0.001924 seconds.

3   Pass
v = [ 150 180 60 40]; s = 1e10; tic res = buy(v, s); toc assert(sum(res) == s); assert(all(ismember(res, v)))

Elapsed time is 0.659704 seconds.

4   Pass
v = [123456, 963852, 753159, 7841, 122]; s = 1e10+19; tic res = buy(v, s); toc assert(sum(res) == s); assert(all(ismember(res, v)))

Elapsed time is 0.007177 seconds.

5   Pass
v = [319,2770,462,972,8235,6949,3171,9503,345,4388,3816,7656,7952,1869,4898,4456,6464,7094,7547,2761,6798,6551,1627,1190,4984,9598,3404,5853,2239,7513]; s = 1e10+19; tic; res = buy(v, s); toc; assert(sum(res) == s); assert(all(ismember(res, v)))

Elapsed time is 0.023045 seconds.

6   Pass
v = [3898,2417,4040,965,1320,9421,9562,5753,598,2348,3532,8212,155,431,1690,6492,7318,6478,4510,5471,2964,7447,1890,6868,1836,3685,6257,7803,812,9294,7758,4868,4359,4468,3064,5086,5108,8177,7949,6444,3787,8116,5329,3508,9391,8760,5502,6225,5871,2078]; s = 1e10+19; tic; res = buy(v, s); toc; assert(sum(res) == s); assert(all(ismember(res, v)))

Elapsed time is 0.008413 seconds.

Suggested Problems

More from this Author4

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!