개발자 톡
연습문제 톡
GBC
JS 코드는 없길래...
- 등록일
- 2024-11-08 05:46:32
- 조회수
- 27
- 작성자
- vavoya6324
const fs = require('fs'); const [NM, ...input] = fs.readFileSync(0, 'utf8').trim().split('\n'); const [N, M] = NM.split(' ').map(Number); const sectionsA = input.slice(0, N).map(v => v.split(' ').map(Number)); const sectionsB = input.slice(N).map(v => v.split(' ').map(Number)); let max = 0; let [Aindex, Bindex] = [0, 0]; while (sectionsA[Aindex] !== undefined && sectionsB[Bindex] !== undefined) { const minRange = Math.min(sectionsA[Aindex][0], sectionsB[Bindex][0]); const speedDif = sectionsB[Bindex][1] - sectionsA[Aindex][1]; max = Math.max(max, speedDif); // 범위 갱신 sectionsA[Aindex][0] -= minRange; sectionsB[Bindex][0] -= minRange; // 인덱스 이동 if (sectionsA[Aindex][0] === 0) Aindex++; if (sectionsB[Bindex][0] === 0) Bindex++; } console.log(max);
#GBC