fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. signed main(){
  4. int x, n;
  5. cin >> x >> n;
  6. priority_queue<int> pq;
  7. priority_queue<int> pq2;
  8. pq2.push(x);
  9. for(int i = 0; i < x; i++){
  10. int st;
  11. cin >> st;
  12. pq.push(-st);
  13.  
  14. }
  15. int ans = 0;
  16. while(pq.size() > 1){
  17. int num = pq2.top();
  18. ans += num - pq.top();
  19. pq2.push(num - pq.top());
  20. pq2.pop();
  21. pq.pop();
  22.  
  23. }
  24. cout << ans << endl;
  25. }
Success #stdin #stdout 0.01s 5288KB
stdin
8 3
2 3 3
stdout
76