Skip to content

Commit

Permalink
카드 합체 놀이
Browse files Browse the repository at this point in the history
  • Loading branch information
yewon-yw authored Aug 20, 2022
1 parent 507df8e commit 3003145
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions greedy_algorithm/15903.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include <iostream>
#include <queue>
using namespace std;
priority_queue<long long int, vector<long long int>, greater<>> q;

int main() {
int n, m, t;
cin >> n >> m;
for (int i = 0; i < n; i++) {
cin >> t;
q.push(t);
}
long long int tmp, sum = 0;
for (int i = 0; i < m; i++) {
tmp = q.top();
q.pop();
tmp += q.top();
q.pop();
q.push(tmp);
q.push(tmp);
}
for (int i = 0; i < n; i++) {
sum += q.top();
q.pop();
}
cout << sum << "\n";
}

0 comments on commit 3003145

Please sign in to comment.