Skip to content

Commit 64bf5fa

Browse files
committed
cses stick divisions
1 parent 3dfe6cb commit 64bf5fa

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

cses/1161.cpp

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* @file 1161.cpp
3+
* @author Naowal Rahman
4+
* @date 2024-02-25 16:54
5+
*/
6+
#include <bits/stdc++.h>
7+
using namespace std;
8+
9+
int main() {
10+
cin.tie(0)->sync_with_stdio(0);
11+
12+
int x, n, d; cin >> x >> n;
13+
priority_queue<int, vector<int>, greater<int>> pq;
14+
while(cin >> d) pq.push(d);
15+
16+
long long cost = 0;
17+
while(pq.size() > 1) {
18+
int f = pq.top(); pq.pop();
19+
int s = pq.top(); pq.pop();
20+
cost += f + s;
21+
pq.push(f + s);
22+
}
23+
24+
cout << cost;
25+
26+
return 0;
27+
}

0 commit comments

Comments
 (0)