After the latest database upgrade, Gigatron has been restarted. Unfortunately, all the partitions are lagging!
Data pipeline team wants to spin up pods and make sure that all partitions are processed in a prompt manner.
Gigatron instead of having partitions now has
partitions.
Partition
has
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
, then it will
take
milliseconds to finish its work. If it is assigned two partitions
and
, then it will take
milliseconds to finish its work.
Data pipeline wants the recovery to take at most milliseconds. What is the minimum number of pods
they need to
spin up such that there is a way to assign the partitions to
pods such that every pod finishes its work in at most
milliseconds?
Constraints
Subtask 1 [1 point]
Subtask 2 [1 point]
Subtask 3 [1 point]
No additional constraints.
Input Specification
The first line of input contains two positive integers, and
.
The next line contains positive integers. The
th integer,
, is the number of milliseconds of work
available on partition
.
Output Specification
Output the minimum number of pods needed in order to recover in 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