| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
STL set 水过#include<cstdio>
#include<iostream>
#include<algorithm>
#include<set>
using namespace std;
int str[20009],n;
typedef long long int LL;
int main(void){
while(~scanf("%d", &n)) {
LL ans = 0;
multiset<int> S;
for(int i = 0; i < n; i++) {
int x;
scanf("%d", &x);
S.insert(x);
}
while(S.size() > 1) {
multiset<int>::iterator it = S.begin();
int temp = *it;
S.erase(it);
it = S.begin();
temp += *it;
S.erase(it);
ans += temp;
S.insert(temp);
}
printf("%lld\n", ans);
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator