Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

STL set 水过

Posted by jibancanyang at 2015-04-10 17:08:32 on Problem 3253
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator