티스토리 뷰

https://www.acmicpc.net/problem/22234.

 

22234번: 가희와 은행

가희는 창구가 하나인 은행을 운영하고 있습니다. 가희의 은행이 영업을 시작했을 때, 대기 줄에는 손님이 N명 있습니다. [그림 1] 카운터 직원과 N명의 손님 x번 손님에 대한 정보는 x번 손님의

www.acmicpc.net

 

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
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/09   »
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
29 30
글 보관함