-
Notifications
You must be signed in to change notification settings - Fork 7
/
Program.cs
52 lines (51 loc) · 1.53 KB
/
Program.cs
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
using System;
using System.Collections.Generic;
namespace CinemaSeatAllocation
{
class Program
{
static void Main(string[] args)
{
int n = 5;
int[][] reservedSeats = new[]
{
new[] {2,2},
new[] {5,4},
new[] {3,5},
new[] {5,10},
new[] {5,7},
new[] {4,5},
};
Console.WriteLine(MaxNumberOfFamilies(n, reservedSeats));
}
static int MaxNumberOfFamilies(int n, int[][] reservedSeats)
{
var rows = new Dictionary<int, HashSet<int>>();
foreach (var reservedSeat in reservedSeats)
{
if(!rows.ContainsKey(reservedSeat[0]))
rows[reservedSeat[0]] = new HashSet<int>();
rows[reservedSeat[0]].Add(reservedSeat[1]);
}
var res = (n - rows.Count) * 2;
foreach (var row in rows)
{
int count = 0;
for (int i = 2; i < 10; i++)
{
if(count == 0 && (i != 2 && i != 4 && i != 6)) continue;
if (!row.Value.Contains(i))
count++;
else
count = 0;
if(count == 4 && (i == 5 || i == 7 || i == 9))
{
res++;
count = 0;
}
}
}
return res;
}
}
}