+ 5

Elevator packing challenge

An elevator has a max load mload (ex: mload=600) & a list of weights of the persons in a group lweight (ex :lweight=[24,44,55,23,44,65,75,120,80,98,45,45]). You want to put the max weight in the elevator while staying under mload Write a program taking mload and lweight as input & outputs a sublist of lweight so that the sum of elements in sublist is as close as possible to mload (but <=). Test: 20 [10 8 8 8 4] 88 [80 21 21 21 21] 600[23,45,33,55,13,66,5,45,54,77,88,122,43,55,580,700,800,601,603,602,710]

23rd Sep 2017, 8:39 AM
VcC
VcC - avatar
24 odpowiedzi
+ 9
Here's my C# implementation! ✌ I wonder if there are any more elegant approach available than simple greedy algorithm with sorting which I've implemented. Happy coding! 😄 ‼ Pending for Bug Fix 🐞 https://code.sololearn.com/cJsu84bimk4x/?ref=app
23rd Sep 2017, 3:49 PM
Zephyr Koo
Zephyr Koo - avatar
+ 7
@VcC I see, got it and I'll try it later. I suggest you to include test case into question as well to allow us to have better understanding. 👌
23rd Sep 2017, 4:30 PM
Zephyr Koo
Zephyr Koo - avatar
+ 5
This challenge is more complicated than I thought as it's a subset-sum problem in disguise. I'll definitely revisit this challenge again once I got what it takes. Good challenge as usual by VcC!!!
25th Sep 2017, 11:16 PM
Zephyr Koo
Zephyr Koo - avatar
23rd Sep 2017, 9:18 AM
Calviղ
Calviղ - avatar
+ 2
fixed for the examples case 😁 plus I'll check others, that makes me remember this https://code.sololearn.com/WFmlWqvA4Jpq/?ref=app
24th Sep 2017, 1:15 PM
ysraelcon
ysraelcon - avatar
23rd Sep 2017, 3:53 PM
Kartik
Kartik - avatar
+ 1
@VcC Output : 1 2 2 3? or 1 2 12 3?
23rd Sep 2017, 4:11 PM
Kartik
Kartik - avatar
+ 1
@VcC Check again Updated
23rd Sep 2017, 4:21 PM
Kartik
Kartik - avatar
24th Sep 2017, 7:35 AM
Arnold
Arnold - avatar
+ 1
goes up https://code.sololearn.com/WC3SE536EY8T/ now goes down and now goes up again 😵 working for: 88 80,21,21,21,21,38,30,20
24th Sep 2017, 10:43 AM
ysraelcon
ysraelcon - avatar
0
You need to put the maximum weight (was mentionned in the challenge and in real life you better use as much as your capacity as possible - you never know what comes in the next groupem) ! Should be 12 2 1
23rd Sep 2017, 4:18 PM
VcC
VcC - avatar
0
what's the output 5 6 6 6 6?
23rd Sep 2017, 4:44 PM
Kartik
Kartik - avatar
0
So Maximum weight in any case Not maximum people???
23rd Sep 2017, 4:49 PM
Kartik
Kartik - avatar
0
Yes. I think that we could also find cases with same nr of people but better weight in your code - just trying to change the last one is not enough.
23rd Sep 2017, 4:52 PM
VcC
VcC - avatar
0
I'm getting max persons as 4 and weight as 6 3 3 3
24th Sep 2017, 7:46 AM
Arnold
Arnold - avatar
0
u must enter the max load first then the number of persons and then the weight of each person
24th Sep 2017, 7:48 AM
Arnold
Arnold - avatar
24th Sep 2017, 9:35 PM
VcC
VcC - avatar
- 1
@kartik. nope. try 15 12 2 2 1
23rd Sep 2017, 4:00 PM
VcC
VcC - avatar
- 1
@calvin : same. Not working for 15 12 2 2 1
23rd Sep 2017, 4:08 PM
VcC
VcC - avatar
- 1
@kartik not maximum with 31 6 6 6 6 6 6 5 20
23rd Sep 2017, 4:37 PM
VcC
VcC - avatar