Supermarket cashier Problem
L recently opened a small supermarket outside the big job. Because the supermarket is inexpensive, and the service attitude is enthusiastic, so just opened a very hot. However, the supermarket currently has only two cash registers, so that recently, customers often complain that the waiting time for payment is too long.
There is no way for the supermarket to add a new checkout at the moment, so I would like to mitigate the problem by other means. Now, suppose there are N customers waiting to be paid. Obviously, the first two customers can get the service right away, and the back will have to wait in line. L want to readjust the two teams so that the average waiting time for these n customers is minimal. Let's say the N customers won't come to new customers until they pay the bill. Please help him to finish the task.
Input
There are multiple sets of data. Each group of data occupies two rows, the first row is a positive integer n (n <= 1000), representing the number of customers waiting to be paid. The second line has n positive integers, representing the time it takes for the N customer to pay (this can be introduced by the number of things the customer buys), in seconds.
Output
For each set of data, please arrange these n customers into these two queues so that the average wait time for these n customers is minimal. A customer's waiting time refers to the time the customer takes from the queue to the start of the payment, not the time of the payment. You only need to output a floating-point number to represent the average waiting time for these customers. The unit is seconds, accurate to 3 digits after the decimal point.
Sample Input
6
16 15 12 14 13 22
Sample Output
13.167
#include <cstdio>
#include <algorithm>
int q[1010], n, ans;
int main () {while
(~scanf ("%d", &n)) {for
(int i = 0; i < n; i++)
scanf ("%d", q + i);
Std::sort (q, q + N);
Ans = 0;
int t = (n + 1)/2;
for (int i = 0; i < n; i + + 2)
ans + = (--t) * Q[i];
t = N-(n+1)/2;
for (int i = 1; i < n; i + + 2)
ans + = (--t) * Q[i];
printf ("%.3lf\n", ans * 1.0/n);
return 0;