#P1223. 排队接水

排队接水

Description

There are nn people lining up at a faucet. Suppose the time each person needs to fill water is TiT_i. Please write a program to find an ordering of these nn people that minimizes the average waiting time of all nn people.

A person's waiting time does not include their own filling time.

If two people have the same filling time, the one with the smaller index should be placed earlier.

Input Format

The first line contains an integer nn.

The second line contains nn integers. The ii-th integer TiT_i denotes the ii-th person's filling time TiT_i.

Output Format

Output two lines. The first line is an ordering that yields the minimum average waiting time. The second line is the average waiting time under this ordering (rounded to two decimal places).

10 
56 12 1 99 1000 234 33 55 99 812
3 2 7 8 1 4 9 6 10 5
291.90

Hint

Constraints: 1n10001 \le n \leq 1000, 1ti1061 \le t_i \leq 10^6. The tit_i are not guaranteed to be distinct.

Translated by ChatGPT 5