Amplitude Hackathon '23 Problem 5 - Partition Assignment

View as PDF

Submit solution

Points: 7 (partial)
Time limit: 2.0s
Memory limit: 1G

Problem type

After the latest database upgrade, Gigatron has been restarted. Unfortunately, all the partitions are lagging! Data pipeline team wants to spin up K pods and make sure that all partitions are processed in a prompt manner.

Gigatron instead of having 1024 partitions now has N partitions. Partition i has t_i milliseconds of work left to do on it. To expedite the rate at which Gigatron recovers, a single pod can be assigned either one partition or two partitions. If it is assigned one partition p_1, then it will take t_{p_1} milliseconds to finish its work. If it is assigned two partitions p_1 and p_2, then it will take t_{p_1} + t_{p_2} milliseconds to finish its work.

Data pipeline wants the recovery to take at most M milliseconds. What is the minimum number of pods K they need to spin up such that there is a way to assign the partitions to K pods such that every pod finishes its work in at most M milliseconds?

Constraints

1 \le N \le 10^6

1 \le t_i \le M \le 10^9

Subtask 1 [1 point]

N \le 12

Subtask 2 [1 point]

N \le 10^3

Subtask 3 [1 point]

No additional constraints.

Input Specification

The first line of input contains two positive integers, N and M.

The next line contains N positive integers. The ith integer, t_i, is the number of milliseconds of work available on partition i.

Output Specification

Output the minimum number of pods needed in order to recover in M milliseconds.

Sample Input 1

5 4
4 3 4 3 4

Sample Output 1

5

Sample Explanation 1

We must spin up one pod per partition in this scenario.

Sample Input 2

5 100
4 3 4 3 4

Sample Output 2

3

Sample Explanation 2

If we spin up three pods, then the first pod can take the first two partitions, the second pod can take partition 3, and the last pod can take the last two partitions.


Comments

There are no comments at the moment.