tot得用double型
接水时间得用int 来读入
#include <bits/stdc++.h>
using namespace std;
int n, t;
double tot;
struct p {
int id;
int time;
} a[10011];
bool cmp(p x, p y) {
return x.time < y.time;
}
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i].time;
a[i].id = i;
}
sort(a + 1, a + 1 + n, cmp);
for (int j = 1; j <= n; j++) {
cout << a[j].id << " ";
}
cout << endl;
for (int j = 1; j <= n - 1; j++) {
tot += a[j].time * (n - j);
}
printf("%.2lf", tot / n);
}