There are n people standing on the first floor. An elevator can carry up to k people.
Everyone has a floor to go. F [1]... f [N]. F [I] belongs to []
It takes ABS (a-B) seconds from layer a to layer B.
Ask the elevator how many seconds it will take to deliver the whole person and return to the first floor.
Ideas:
Sort the floors that everyone wants to go from small to large.
First, send the upper-level personnel to the lower-level personnel, and then send K at a time. (Proof: to send the highest level of the person's trip (complete) at least ** time, in this trip "by the belt" To Go To The K-1 high-rise building people to complete)
Code:
Int N, K; int f [2005]; int main () {scanf ("% d", & N, & K); rep (I, 0, n-1) scanf ("% d", & F [I]); sort (F, F + n); int ans = 0; For (INT I = n-1; I> = 0; i-= k) {ans + = (f [I]-1) * 2);} printf ("% d \ n", ANS );}
Cf learn from life (simple and greedy)