티스토리 뷰
https://www.acmicpc.net/problem/22234.
class Node {
constructor(item) {
this.item = item;
this.next = null;
}
}
class Queue {
constructor() {
this.head = null;
this.tail = null;
this.length = 0;
}
push(item) {
const node = new Node(item);
if (this.head == null) {
this.head = node;
} else {
this.tail.next = node;
}
this.tail = node;
this.length += 1;
}
pop() {
const popItem = this.head;
this.head = this.head.next;
this.length -= 1;
return popItem.item;
}
}
const readline = require('readline').createInterface({
input: process.stdin,
output: process.stdout,
});
const input = new Queue();
readline.on('line', function (line) {
input.push(line.split(' ').map(Number));
}).on('close', function () {
const newGogaek = Array(100001);
const q = new Queue();
const [N, T, W] = input.pop();
for (let i = 0; i < N; i++) {
const [p, t] = input.pop();
q.push([p, t]);
}
const [M] = input.pop();
for (let i = 0; i < M; i++) {
const [p, t, c] = input.pop();
newGogaek[c] = [p, t];
}
let w = 0;
const answer = [];
while (true) {
const [p, t] = q.pop();
const tx = Math.min(T, t);
for (let i = 1; i <= tx; i++) {
w += 1;
answer.push(p);
if (newGogaek[w]) {
q.push(newGogaek[w]);
}
if (w == W) {
console.log(answer.slice(0, W).join('\n'));
process.exit(0);
}
}
if (t - tx > 0) {
q.push([p, t - tx]);
}
}
});
728x90
'자료구조 알고리즘 > 백준' 카테고리의 다른 글
Node.js) 백준 29807번: 학번을 찾아줘! (0) | 2023.09.16 |
---|---|
Node.js) 백준 29790번: 임스의 메이플컵 (0) | 2023.09.15 |
Node.js) 백준 20157번: 화살을 쏘자! (0) | 2023.09.14 |
Node.js) 백준 17839번: Baba is Rabbit (0) | 2023.09.13 |
Node.js) 백준 20311번: 화학 실험 (0) | 2023.09.13 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 다이나밍프로그래밍
- 개발자면접
- MOD
- 롱베케이션
- 그래프
- 면접비
- DB 생성
- 최소공통조상
- create databases;
- BFS
- 서버개발
- 동적프로그래밍
- 투포인터 연습
- node.js
- create db
- 다이나믹프로그래밍
- 면접질문
- 은둔청년체험
- 서버점검
- 투포인터
- 로드나인
- MySQL
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
글 보관함