-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaddAll.cpp
57 lines (48 loc) · 1.06 KB
/
addAll.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <algorithm>
#include <fstream>
#include <functional>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
int main()
{
ifstream fin("addAll.in");
ofstream fout("addAll.out");
while (true)
{
int total, ans = 0;
fin >> total;
priority_queue<int, vector<int>, greater<int>> a;
if (total == 0)
{
break;
}
for (int i = 1; i <= total; ++i)
{
int temp;
fin >> temp;
a.push(temp);
}
while (!(a.empty()))
{
int sum = a.top();
//cout << sum << " + ";
a.pop();
if (a.empty() == true)
{
break;
}
sum += a.top();
//cout << a.top() << " = ";
a.pop();
a.push(sum);
ans += sum;
//cout << sum << '\n';
}
fout << ans << endl;
}
return 0;
}