As a logistics manager in an automobile manufacturing company, you are responsible for storing deliveries in secure warehouses.
You are given an array deliveryLogs of size n, where each element represents the number of parts delivered in the i-th log. You are also given an even integer k, representing the number of secure warehouses available.
When deliveries are stored:
k/2 warehouses with the largest number of deliveries will become compromised.k/2 warehouses are safe, and only the deliveries in them are counted as secure.Your task is to find the maximum number of secure deliveries that can be stored.
Complete the function secureMaximumDeliveries.
secureMaximumDeliveries has the following parameter(s):
int deliveryLogs[n]: the number of deliveries in the i-th encrypted log.int k: the number of secure warehouses you have.Returns:
int: the maximum number of secure deliveries you can make.1 <= n <= 10002 <= k <= 10000 <= deliveryLogs[i] <= 1000k is an even integer.Sample Input 0
n = 1
deliveryLogs = [6]
k = 2
Sample Output 0
3
Explanation If we decode half the deliveries and store them in the first secure warehouse, then decode the remaining half and store them in the second warehouse, each warehouse will have three deliveries. One of these warehouses will be compromised since they have an equal number of deliveries, so the remaining secure deliveries will be 3.
Sample Input 1
n = 6
deliveryLogs = [5, 5, 5, 5, 5, 5]
k = 4
Sample Output 1
10
Explanation Decrypt all the deliveries in any of the four logs and store them in the secure warehouses. Now, all secure warehouses have five deliveries each. After two warehouses are compromised, the total secure deliveries are 5 + 5 = 10.
Amazon • Pending