82分,求助!

P1223 排队接水

@[RockyChen](/user/810200) ``` #include <bits/stdc++.h> using namespace std; struct node { int id; int t; } a[1000001]; int cmp(node x, node y) { if (x.t != y.t) return x.t < y.t; if (x.id != y.id) { return x.id < y.id; } } long long n, ans; int main() { cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i].t; a[i].id = i; } sort(a + 1, a + n + 1, cmp); for (int i = 1; i < n; i++) { ans += (n - i) * a[i].t; } for (int i = 1; i <= n; i++) { cout << a[i].id << " "; } cout << endl; cout << fixed << setprecision(2) << ans * 1.0 / n ; return 0; }
by C13408964921 @ 2023-10-09 19:25:50


@[RockyChen](/user/810200) ``` int n, ans;//这没开long long ```
by C13408964921 @ 2023-10-09 19:27:41


@[C13408964921](/user/766647) ,谢谢帮助!
by RockyChen @ 2023-10-14 08:02:13


好了,此帖结
by RockyChen @ 2023-10-14 08:02:50


|