| ||||||||||
| 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 | |||||||||
Re:priority_queue 一直WA。。求高人In Reply To:priority_queue 一直WA。。求高人 Posted by:zhrln at 2013-04-12 19:41:03 > #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;
> }
long long
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator