We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent f6bf3ce commit d22d40cCopy full SHA for d22d40c
2 files changed
서정우/10주차/260303.js
@@ -0,0 +1,28 @@
1
+const fs = require("fs");
2
+const filePath = process.platform === "linux" ? "/dev/stdin" : "./서정우/input.txt";
3
+const input = fs
4
+ .readFileSync(filePath)
5
+ .toString()
6
+ .trim()
7
+ .split("\n")
8
+ .map((el) => el.trim());
9
+
10
+const [N, M] = input[0].split(" ").map(Number);
11
+const holes = input[1].split(" ").map(Number);
12
13
+let maxDistance = 0;
14
+let distance = 0;
15
+let left = 0;
16
17
+for (let i = 0; i < N; i++) {
18
+ distance += holes[i];
19
20
+ while (distance > M) {
21
+ distance -= holes[left];
22
+ left++;
23
+ }
24
25
+ maxDistance = Math.max(maxDistance, distance);
26
+}
27
28
+console.log(maxDistance);
서정우/input.txt
@@ -1,7 +1,2 @@
-6
-4
-5
+8 10
+2 2 2 2 11 2 5 2
0 commit comments