记录编号 369167 评测结果 AAAAAAAAAA
题目名称 [NOIP 2004]合并果子 最终得分 100
用户昵称 Gravataryzh-- 是否通过 通过
代码语言 C++ 运行时间 0.040 s
提交时间 2017-02-08 11:40:12 内存使用 0.31 MiB
显示代码纯文本
  1. #include<iostream>
  2. #include<queue>
  3. #include<cstdio>
  4. using namespace std;
  5. int n;
  6. priority_queue<int,vector<int>,greater<int> >h;
  7. void work()
  8. {
  9. int i,x,y,ans=0;
  10. cin>>n;
  11. for(i=1;i<=n;i++)
  12. {
  13. cin>>x;
  14. h.push(x);
  15. }
  16. for(i=1;i<n;i++)
  17. {
  18. x=h.top();h.pop();
  19. y=h.top();h.pop();
  20. ans+=x+y;
  21. h.push(x+y);
  22. }
  23. cout<<ans<<endl;
  24. }
  25. int main()
  26. {
  27. freopen("fruit.in","r",stdin);
  28. freopen("fruit.out","w",stdout);
  29. work();
  30. return 0;
  31. }