Skip to content

Commit ceb9fe7

Browse files
authored
Merge pull request #522 from dongmin115/main
[임동민] 64차 라이브코테 제출
2 parents 77952eb + b4a31e3 commit ceb9fe7

File tree

3 files changed

+87
-0
lines changed

3 files changed

+87
-0
lines changed

live6/test64/문제1/임동민.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
const input = require('fs')
2+
.readFileSync(process.platform === 'linux' ? '/dev/stdin' : './input.txt')
3+
.toString()
4+
.trim()
5+
.split('')
6+
.map(Number);
7+
8+
function solution() {
9+
input.sort((a,b) => b - a);
10+
const sum = input.reduce((a,b) => a + b, 0);
11+
12+
if(sum % 3 !== 0 || input[input.length -1] !== 0){
13+
console.log(-1);
14+
} else {
15+
console.log(input.join(''));
16+
}
17+
}
18+
19+
solution();

live6/test64/문제2/임동민.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
const input = require('fs')
2+
.readFileSync(process.platform === 'linux' ? '/dev/stdin' : './input.txt')
3+
.toString()
4+
.trim()
5+
.split('\n')
6+
.map(e => e.split(' ').map(Number));
7+
8+
function solution() {
9+
const [N,K] = input[0];
10+
const testCase = input.slice(1);
11+
let sum = 0;
12+
const window = 2 * K + 1;
13+
14+
let maxPosition = 0;
15+
16+
for (let i = 0; i < N; i++) {
17+
const [, position] = testCase[i];
18+
if (position > maxPosition) maxPosition = position;
19+
}
20+
21+
const arr = new Array(maxPosition+1).fill(0);
22+
23+
testCase.forEach(([ices,position]) => {
24+
arr[position] += ices;
25+
})
26+
27+
for(let i=0; i<= Math.min(maxPosition, window - 1); i++) {
28+
sum += arr[i];
29+
}
30+
31+
let max = sum;
32+
33+
for(let i=window; i<=maxPosition; i++) {
34+
sum += arr[i] - arr[i-window];
35+
max = Math.max(max, sum);
36+
}
37+
38+
console.log(max);
39+
}
40+
41+
solution();

live6/test64/문제3/임동민.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
function solution(cacheSize, cities) {
2+
const stack = [];
3+
let time = 0;
4+
5+
if(cacheSize === 0){
6+
return cities.length * 5;
7+
}
8+
9+
cities.forEach(e => {
10+
const lower = e.toLowerCase();
11+
if(stack.includes(lower)){
12+
time += 1;
13+
stack.splice(stack.indexOf(lower),1);
14+
stack.push(lower);
15+
} else {
16+
time += 5;
17+
18+
if(stack.length >= cacheSize){
19+
stack.shift();
20+
}
21+
22+
stack.push(lower);
23+
}
24+
25+
})
26+
return time;
27+
}

0 commit comments

Comments
 (0)