Boba has opened a toy-manufacturing company that has workers, where exactly workers are newbies and the rest workers are experienced. Each toy can be made by exactly one worker, but all workers can work in parallel on different toys. However, if an experienced worker takes time to complete one toy of a specific design, a newbie takes to make the same toy (simply, twice as much time).
Boba's very good friend Kiki wants toys, each with different designs. Boba has done his calculations and prepared a dataset on how much time an experienced worker will need to complete each toy. Formally, he has prepared an array where the -th element denotes the amount of time an experienced worker will take to complete the -th toy.
Now, Boba has asked for your help to calculate the minimum amount of time required to complete all toys, if he assigns the workers to each toy optimally, also ensuring that every worker will work on at least one toy.
The first line contains an integer denoting the number of toys Kiki wants.
The second line contains space-separated integers denoting the array , where the -th element denotes the time an experienced worker will take to complete the -th toy.
The third line contains an integer denoting the number of workers who are newbies.
Print an integer in a single line denoting the minimum amount of time required to complete all toys in the given scenario.
Input | Output |
---|---|
3 5 11 8 1 | 11 |
The only newbie worker should work on the first toy. |
Input | Output |
---|---|
3 7 13 7 2 | 14 |
The two newbie workers should work on the first toy and the third toy respectively. |