The task is similar to the previous question , only here the goal is different, initially the task was misunderstood. In the previous task, it was necessary to calculate the maximum number of people accommodated in the elevator, and in this we should maximally load the elevator. Initially, the task was not properly understood. A list of people with a name and weight is given, the maximum weight that the lift can withstand. Calculate the maximum weight that can fit and display a list of what people fit to load the elevator as much as possible.
I do not understand how to determine the combination of people that may be. After all, there may be different combinations, 1, 2, 3 or 1, 2, 4, or 1, 3, 5, 6. I want to first find out all the possible combinations of capable people and then display the maximum. But how to find out the combinations of these people or how such problems are solved differently.
public class MaxLift { public static void main(String[] args) { Man[] men = new Man[10]; men[0] = new Man("0", 110); men[1] = new Man("1", 30); men[2] = new Man("2", 34); men[3] = new Man("3", 67); men[4] = new Man("4", 33); men[5] = new Man("5", 65); men[6] = new Man("6", 19); men[7] = new Man("7", 80); men[8] = new Man("8", 98); men[9] = new Man("9", 45); int liftMaxWeight = 200; TreeSet<List<Man>> set = new TreeSet<>();//add comparator for (int i = 0; i < men.length; i++) { List<Man> list = new ArrayList<>(); list.add() } //sout } private static class Man { String name; int weight; public Man(String name, int weight) { this.name = name; this.weight = weight; } } }