Skip to content

Instantly share code, notes, and snippets.

@draqoon
Created June 9, 2015 06:10
Show Gist options
  • Save draqoon/ebae460f0021afdd2b9f to your computer and use it in GitHub Desktop.
Save draqoon/ebae460f0021afdd2b9f to your computer and use it in GitHub Desktop.
//Paiza Lerning 長テーブルのうなぎ屋 (paizaランク B 相当)
//https://paiza.jp/learning/long-table
using System;
using System.Collections.Generic;
public class Program {
public static void Main() {
var s = Console.ReadLine().Split( ' ' );
var chairCount = int.Parse( s[0] ); //座席数
var groupCount = int.Parse( s[1] ); //グループ数
var chairs = new bool[chairCount];
while( 0 < groupCount ) {
groupCount -= 1;
s = Console.ReadLine().Split( ' ' );
var personCount = int.Parse( s[0] ); //グループ人数
var startPos = int.Parse( s[1] ) - 1; //着席開始位置
var canSit = true;
for( var i = 0; i < personCount; i++ ) {
var p = startPos + i;
if( chairCount - 1 < p ) {
p -= chairCount;
}
if( chairs[p] ) {
canSit = false;
break;
}
}
if( canSit ) {
for( var i = 0; i < personCount; i++ ) {
var p = startPos + i;
if( chairCount - 1 < p ) {
p -= chairCount;
}
chairs[p] = true;
}
}
}
var count = 0;
for( var i = 0; i < chairCount; i++ ) {
if( chairs[i] )
count += 1;
}
Console.WriteLine( count );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment