Airlift
You and your family are trapped on a flood-prone island.When you called the emergency services to ask for assistance . They promised to send aircraft to airlift your family. As long as the combined weight of the two passengers is less than or equal to K
,each aircraft is only permitted to to carry a maxmum of K and a maximum of K and a maximum of two other passengers in addition to the pilot . You are given the following
- The maximum capacity of the aircraft
- The total number of family members
- An array weights where weights[i], reprsent the weight of the ith family member
Task
Return the minimum number of aircraft required to airlift the family
If not possible, return -1.
Example
Assumptions:
K = 5
N= 9
weights = [3,3,5,2,1,4,5,1,5]
Constraints
1 <= K <= 5*109
1 <= N <= 105
1 <= weights[i] <= 109
weights contain only positive integers
Sample Input Sample Output
6 3
4
3 5 4 3
Shopping and billing
In a shop wth N counters. M peccie arrive for billing at different times denoted as smell. Each person selects the counter with the shortest queue, based on the number of people already present. if a counter is empty the pets immediate biting, otherefse, they join the queue
For every person, output the tit
rig and leave the counter.
Notes
- It takes 1 unit of time for the counter to process a person's bills
- The counter processess the next person mmediately after the current person leaves .
- The time is given in increasing order of arrival at the counters . In formal terms time[i] <= time[i+1]
Function Description
Complete the function solve . This function takes the following 3 parameters returns teh required answer
- N- Represents the numer of counters
- M: Represents the number of persons
- tiime: Represents an array containing the entry time of the people
Input format for custom testing
Note: Use this input format if you are testing against custom Input or writing code in a language
where we don't provide bollerplate code.
- The first line contains N denoting the number of counters.
- The second line contains M denoting the number of persons.
- The third line contains an array time, indicating the entry time of the people.
Output format
Print a single line of M space-separated integers, denoting the exit times of the people.
Constraints
1<= N <= 105
1 <= M <= 105
0 <= position[i] <= 109
Sample Input Sample Output
2 1 1 2 2
4
0 0 0 0
Explanation
N=2
M=4
position = |0, 0. 0. 0]
Output
1 1 2 2
- The first person arrives at O, finds both counters empty, goes to counter 1, and leaves at
- The second person arrives at 0, finds counter 2 empty, and leaves at 1
- The third person arrives at 0, finds both counters with 1 person, goes to counter 2, and leaves at 2
- The fourth person arrives at 0, finds counter 1 with 1 person and counter 2 with 2 persons, goes to counter 1 and leaves at 2
Sample Input Sample Output
10 88234 93641 99414 99901 99990 99994 99997 99997 99
31
88233 93640 99410 99900 99989 99993 99996
Special Package
You are the manager of a grocery store and you want to create special package deal for your customers . you are given a matrix of prices of size N * M . for different products ,with each row representing different category of products and esch column representing a different product in the category
You want to select one item from each category such that the total cost of the package is as close as possible to a specific target price K
You need to determine the minimum absolute difference between targer price and actual cost of the package you can create products in the matrix
Fuction Description
Complete the function solution() provided in the editor .The function takes the following 4 parameters and return the solution
- N: Represents the number of categories
- M:Represents the number of items in each category
- K: Repreents the target price
- price: represents the price of items
Input format for custom testing
Note: Use this input format if you are testing against custom input or writing code in a language
where we don't provide boilerplate code
The first line contains N denoting the number of categories.
The second line contains M denoting the number of items in each category.
* The third line contains K denoting the target price.
• Each of the next N lines contains M integers each, denoting the price of the items.
Output format
Print an integer, representing the minimum absolute difference between the target price and the total cost of the package.
Constraints
1 <= N,M <= 70
1 <= price[i][j] <= 70
1 <= K <= 800
Question 1 solution