比赛 test1 评测结果 AAAAAAAAAA
题目名称 合并果子 最终得分 100
用户昵称 Regnig Etalsnart 运行时间 0.043 s
代码语言 C++ 内存使用 0.31 MiB
提交时间 2017-02-28 20:40:38
显示代码纯文本
  1. #include<iostream>
  2. #include<cstdio>
  3. #include<queue>
  4. using namespace std;
  5. int n;
  6. priority_queue<int,vector<int>,greater<int> >h;
  7. int main()
  8. {
  9. freopen("fruit.in","r",stdin);freopen("fruit.out","w",stdout);
  10. int i,x,y,ans=0;
  11. scanf("%d",&n);
  12. for(i=1;i<=n;i++)
  13. {
  14. scanf("%d",&x);
  15. h.push(x);
  16. }
  17. for(i=1;i<n;i++)
  18. {
  19. x=h.top();
  20. h.pop();
  21. y=h.top();
  22. h.pop();
  23. ans+=x+y;
  24. h.push(x+y);
  25. }
  26. printf("%d",ans);
  27. return 0;
  28. fclose(stdin);fclose(stdout);
  29. }