๋ฌธ์ ๋งํฌ
https://www.acmicpc.net/problem/18111
๋ฌธ์ ํ์ด
๋ฌธ์ ๋ฅผ ํธ๋ฉด์ ์๋์ ๊ฐ์ด ๋ช ๊ฐ์ง ์ ์ํ ์ ๋ง ์ฃผ์ํ๋ฉด ์ฝ๊ฒ ํ ์ ์๋ค.
- ์ต์ข ๋ ์ ๋์ด๋ 256์ ์ด๊ณผ ํ ์ ์๋ค.
- ์ต์์๊ฐ์ด ๊ฑธ๋ฆฌ๋ ๋ ์ ๋์ด๊ฐ ์ฌ๋ฌ๊ฐ ์ผ ๊ฒฝ์ฐ ๊ฐ์ฅ ๋์ ๋ ์ ๋์ด๋ฅผ ์ถ๋ ฅํ๋ค.
let fs = require("fs");
let input = fs.readFileSync("/dev/stdin").toString().trim().split("\n");
let [info, ...arr] = input;
let [N, M, B] = info.split(" ").map((n) => Number(n));
let set = [];
arr = arr.map((line) => {
let lineArr = line.split(" ").map((n) => Number(n));
lineArr.forEach((v) => {
if (!set.includes(v)) {
set.push(v);
}
});
return lineArr;
});
let [minH, maxH] = [Math.min(...set), Math.max(...set)];
let spendTime = Infinity;
let proper_height = undefined;
for (let h = minH; h <= maxH; ++h) {
if (h > 256) {
break;
}
let block = B;
let time = 0;
for (let r = 0; r < N; ++r) {
for (let c = 0; c < M; ++c) {
let height = arr[r][c];
if (height !== h) {
if (height > h) {
block += height - h;
time += 2 * (height - h);
} else {
block -= h - height;
time += h - height;
}
}
}
}
if (block >= 0 && time <= spendTime) {
spendTime = time;
proper_height = h;
}
}
console.log(spendTime + " " + proper_height);
'๐Algorithm' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
๋ฐฑ์ค[JS] > 11047๋ฒ ๋์ 0 (0) | 2025.02.02 |
---|---|
๋ฐฑ์ค[JS] > 7569๋ฒ ํ ๋งํ (0) | 2025.01.28 |
๋ฐฑ์ค[JS] > 1764๋ฒ ๋ฃ๋ณด์ก (0) | 2025.01.23 |
๋ฐฑ์ค[JS] > 1238๋ฒ ํํฐ (0) | 2025.01.21 |
๋ฐฑ์ค[JS] > 18870๋ฒ ์ขํ ์์ถ (0) | 2025.01.18 |