1. 程式人生 > >P1223 排隊接水

P1223 排隊接水

#include<bits/stdc++.h> 
using namespace std;
struct Node{
	int id;
	int cost;
};
bool cmp(Node a,Node b){
	return a.cost<b.cost;
}
int main()
{
	freopen("in.txt","r",stdin);
	int n;cin>>n;vector<Node> ppp;ppp.resize(n);
	for(int i=0;i<n;i++){
		cin>>ppp[i].cost;ppp[i].id=i+1;
	}
	sort(ppp.begin(),ppp.end(),cmp);
	double ans=0;double waittime=0;
	for(int i=0;i<n;i++){
		if(i==0) cout<<ppp[i].id;
		else cout<<' '<<ppp[i].id;
		ans+=waittime;
		waittime+=ppp[i].cost;
	}
	cout<<endl;
	printf("%.2lf",ans/(n*1.0));
	return 0;
}