比赛 贪心题目练习 评测结果 AAAAAAAAAA
题目名称 合并果子 最终得分 100
用户昵称 Cogito 运行时间 0.086 s
代码语言 C++ 内存使用 3.39 MiB
提交时间 2025-03-22 14:38:03
显示代码纯文本
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int n,res;
  5. priority_queue<int> q;
  6.  
  7. int main () {
  8. freopen("fruit.in","r",stdin);
  9. freopen("fruit.out","w",stdout);
  10. cin >> n;
  11. int x;
  12. for (int i = 1; i <= n; ++i) {
  13. cin >> x;
  14. q.push(-x);
  15. }
  16. while (q.size() > 1) {
  17. int a = -q.top();
  18. q.pop();
  19. a += -q.top();
  20. q.pop();
  21. q.push(-a);
  22. res+=a;
  23. }
  24. cout << res;
  25. return 0;
  26. }