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

priority_queue 一直WA。。求高人

Posted by zhrln at 2013-04-12 19:41:03 on Problem 3253
#include <iostream>
#include <queue>
using namespace std;
priority_queue<int> q;
int main(){
    int n;
	while (cin >> n){
	    int ans=0;
	    for (int i(1);i<=n;i++){
	        int k;
	        cin >> k;
	        q.push(-k);
	    }
	    while (q.size()>1){
	        int a=q.top();
	        q.pop();
	        int b=q.top();
	        q.pop();
	        ans+=a+b;
	        q.push(a+b);
	    }
	    q.pop();
	    cout << -ans << endl;
	}
	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