Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 62770c5

Browse files
priyanka and toys
1 parent 236ea6a commit 62770c5

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

‎priyanka-and-toys.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
'use strict';
2+
3+
const fs = require('fs');
4+
5+
process.stdin.resume();
6+
process.stdin.setEncoding('utf-8');
7+
8+
let inputString = '';
9+
let currentLine = 0;
10+
11+
process.stdin.on('data', inputStdin => {
12+
inputString += inputStdin;
13+
});
14+
15+
process.stdin.on('end', _ => {
16+
inputString = inputString.replace(/\s*$/, '')
17+
.split('\n')
18+
.map(str => str.replace(/\s*$/, ''));
19+
20+
main();
21+
});
22+
23+
function readLine() {
24+
return inputString[currentLine++];
25+
}
26+
27+
// Complete the toys function below.
28+
function toys(w) {
29+
w = w.sort((x,y)=>x-y);
30+
let count = 1;
31+
let check = w.shift() + 4;
32+
w.forEach(x => {
33+
if (x > check) {
34+
count++;
35+
check = x + 4;
36+
}
37+
});
38+
return count;
39+
}
40+
41+
function main() {
42+
const ws = fs.createWriteStream(process.env.OUTPUT_PATH);
43+
44+
const n = parseInt(readLine(), 10);
45+
46+
const w = readLine().split(' ').map(wTemp => parseInt(wTemp, 10));
47+
48+
let result = toys(w);
49+
50+
ws.write(result + "\n");
51+
52+
ws.end();
53+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /