Skip to content

Commit 6db528c

Browse files
[BOJ] 33524 blobnom.xyz (S3)
1 parent 1ec26a6 commit 6db528c

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

서정우/3주차/260115.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// https://www.acmicpc.net/problem/33524
2+
3+
const fs = require("fs");
4+
const filePath = process.platform === "linux" ? "/dev/stdin" : "../input.txt";
5+
const input = fs.readFileSync(filePath).toString().trim().split("\n");
6+
7+
const [N, M] = input[0].split(" ").map(Number);
8+
const problems = input[1].split(" ").map(Number);
9+
const users = input[2].split(" ").map(Number);
10+
11+
const sizes = [0];
12+
for (let i = 1; ; i++) {
13+
const size = 3 * i * (i - 1) + 1;
14+
if (size > N) break;
15+
sizes.push(size);
16+
}
17+
18+
problems.sort((a, b) => a - b);
19+
20+
const upperBound = (arr, target) => {
21+
let l = 0;
22+
let r = arr.length;
23+
while (l < r) {
24+
const mid = (l + r) >> 1;
25+
if (arr[mid] <= target) l = mid + 1;
26+
else r = mid;
27+
}
28+
return l;
29+
};
30+
31+
const result = users.map((userSkill) => {
32+
const count = upperBound(problems, userSkill);
33+
if (count === 0) return 0;
34+
35+
let left = 0;
36+
let right = sizes.length - 1;
37+
let max = 0;
38+
39+
while (left <= right) {
40+
const mid = (left + right) >> 1;
41+
if (sizes[mid] <= count) {
42+
max = mid;
43+
left = mid + 1;
44+
} else {
45+
right = mid - 1;
46+
}
47+
}
48+
return max;
49+
});
50+
51+
console.log(result.join(" "));

0 commit comments

Comments
 (0)