Skip to content

Commit

Permalink
23-카드-합체놀이
Browse files Browse the repository at this point in the history
  • Loading branch information
minbr0ther committed Apr 4, 2022
1 parent 667c140 commit bdbba94
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
15 changes: 15 additions & 0 deletions 2022/greedy/19~24/23-카드-합체-놀이/app.js
@@ -0,0 +1,15 @@
const fs = require('fs');
const filePath = process.platform === 'linux' ? '/dev/stdin' : './input.txt';
let input = fs.readFileSync(filePath).toString().trim().split('\n');

let [n, m] = input.shift().split(' ').map(Number);
const arr = input.shift().split(' ').map(Number);

for (let i = 0; i < m; i++) {
arr.sort();
const sum = BigInt(arr[0]) + BigInt(arr[1]);
arr[0] = sum;
arr[1] = sum;
}

console.log(arr.reduce((a, b) => BigInt(a) + BigInt(b)).toString());
2 changes: 2 additions & 0 deletions 2022/greedy/19~24/23-카드-합체-놀이/input.txt
@@ -0,0 +1,2 @@
3 1
3 2 6

0 comments on commit bdbba94

Please sign in to comment.