@[Simon_Lu](/user/222555)
ans需要开 long long,因为他在累加过程中可能超过int的最大值
```cpp
#include<bits/stdc++.h>
using namespace std;
int n;
long long ans;
struct T{
int t,id;
}a[1005];
bool cmp(T x,T y){
return x.t<y.t;
}
int main(){
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i].t;
a[i].id=i;
}
sort(a+1,a+1+n,cmp);
for(int i=1;i<=n;i++)
ans+=a[i].t*(n-i);
for(int i=1;i<=n;i++)
cout<<a[i].id<<' ';
cout<<endl;
printf("%.2lf",1.0*ans/n);
return 0;
}
```
by YGB_XU @ 2022-03-16 00:02:44
另外这一行应该是 `ans+=a[i].t*(n-i);` 吧
by YGB_XU @ 2022-03-16 00:04:27
@[YGB_XU](/user/164580) 膜拜,我本来也是82分(没开longlong),感谢大佬
by LMS_yr @ 2022-03-16 12:22:29
@[YGB_XU](/user/164580) 非常感谢!
by Simon_Lu @ 2022-03-16 12:47:23