-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path1205.js
More file actions
31 lines (27 loc) · 786 Bytes
/
1205.js
File metadata and controls
31 lines (27 loc) · 786 Bytes
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
/*
현재 랭킹리스트에서 태수보다 점수가 낮은애들 다 제거
넣을 수 있으면 태수점수 넣고 등수계산
없으면 -1
*/
// input
const INPUT_FILE = process.platform === 'linux' ? '/dev/stdin' : './input';
const [N, newScore, maxRankingLength, ...ranking] = require('fs').readFileSync(INPUT_FILE).toString().trim()
.split(/\s/)
.map(Number);
// process
while (ranking[ranking.length - 1] < newScore) ranking.pop();
let sol = -1;
if (ranking.length < maxRankingLength) {
ranking.push(newScore);
let currentRank = 0;
let currentRankScore = -1;
ranking.forEach((score, index) => {
if (score !== currentRankScore) {
currentRank = index + 1;
currentRankScore = score;
}
});
sol = currentRank;
}
// output
console.log(sol);