## Editorial for CPC '19 Contest 1 P2 - Luggage

Remember to use this editorial

**only**when stuck, and**not to copy-paste code from it**. Please be respectful to the problem author and editorialist.**Submitting an official solution before solving the problem yourself is a bannable offence.**Author:

##### Subtask 1

For this subtask, you can simply brute force all subsets of the items and pick the largest subset with a height range .

**Time Complexity:**

##### Subtask 2

Note that it is always advantageous to pick items with as close of a height as possible. Therefore, if you sort the items the question simply becomes finding the largest subarray with a height range . Brute forcing all subarrays and picking the largest one with a height range is fast enough for the second subtask. Finding the height range of a subarray from indices to is simply since the array is sorted.

**Time Complexity:**

##### Subtask 3

To get full points, you have to optimize the brute force from subtask 2 to either binary search or a two-pointer method.

**Time Complexity:**

## Comments