長テーブルのうなぎ屋 (JavaScript)

/** 長テーブルのうなぎ屋 (paizaランク B 相当) https://paiza.jp/works/m […]

/** 長テーブルのうなぎ屋 (paizaランク B 相当) https://paiza.jp/works/m […]

  • タグ:
  • タグはありません
/**
長テーブルのうなぎ屋 (paizaランク B 相当)
https://paiza.jp/works/mondai/skillcheck_sample/long-table?language_uid=javascript
**/

"use strict";
const rl=require("readline").createInterface(process.stdin);

function* rl2val(){
	return (yield rl.once("line",s=>g.next(s)))
		.split(/ /)
		.map(s=>parseInt(s,10));
}

const g=function*(){
	// n:座席数 m:グループ数
	let [n,m]=yield* rl2val();
	const table=new Array(n).fill(false);

	check:
	for(let i=0;i<m;i++){
		// a:グループの人数 b:着席開始座席番号
		let [a,b]=yield* rl2val();
		b--;
		for(let j=0;j<a;j++)
			if(table[(b+j)%n]) continue check;
		for(let j=0;j<a;j++)
			table[(b+j)%n]=true;
	}
	console.log(table.filter(a=>a).length);
	process.exit();
}();
g.next();