打热水


寝室楼里只有热水间能接热水,且每天烧水机器只在指定时间工作,去晚了机器就关掉了,每天晚上去接热水的同学能排起小长队。

某天在总计四个烧水机中,坏了三个只剩下一台机器能打水了。

现在有 n 名同学等待接水,因为每名同学所带的水壶有大有小,规格各不相同所以他们每人的接水时间分别为 Ti,

现求一个顺序,使得所有接水的同学平均等待接水时间最小,等待接水时间为该同学之前接水的同学所花费时间和。

输入

第一行一个整数 n。(1 ≤ n ≤ 30)

第二行 n 个整数表示 Ti。(1 ≤ Ti ≤ 2000)

输出

第一行输出排队顺序

第二行输出平均等待时间,结果保留两位小数。

样例

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

参考代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;

struct node {
int cnt;//打水同学的编号
int time;//所需的打水时间
};

node stu[35];
int n;//同学的数量

bool cmp(const node &a, const node &b) {
return a.time < b.time;
}

int main() {
//1.数据存储
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> stu[i].time;
stu[i].cnt = i;
}
//2.数据处理
sort(stu + 1, stu + n + 1, cmp);
int sum = 0;//总打水时间
int now = 0;//某个同学的打水等待时间
for (int i = 1; i <= n; ++i) {
if (i != 1) cout << " ";
cout << stu[i].cnt;
sum += now;
now += stu[i].time;
}
cout << endl;
printf("%.2f\n", (double)sum / n);
return 0;
}