+ 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]
24 Antworten
+ 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
+ 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. 👌
+ 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!!!
+ 2
fixed for the examples case 😁 plus I'll check others,
that makes me remember this https://code.sololearn.com/WFmlWqvA4Jpq/?ref=app
+ 1
Python implementation:
https://code.sololearn.com/cV72fDcyLZgy/?ref=app
+ 1
@VcC
Output :
1 2 2
3?
or
1 2 12
3?
+ 1
@VcC
Check again
Updated
+ 1
try this code
https://code.sololearn.com/cvg7IW8QOW14/?ref=app
+ 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
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
0
what's the output
5 6 6 6 6?
0
So
Maximum weight in any case
Not maximum people???
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.
0
I'm getting max persons as 4 and weight as
6 3 3 3
0
u must enter the max load first then
the number of persons and then
the weight of each person
- 1
@kartik. nope. try 15
12 2 2 1
- 1
@calvin : same. Not working for 15
12 2 2 1
- 1
@kartik not maximum with 31
6 6 6 6 6 6 5 20