SRM414 DIV2 Level.1
ちょっと時間かかった。
public class Pair<T, U> { public Pair() { } public Pair(T first, U second) { this.First = first; this.Second = second; } public T First; public U Second; } public class RestaurantManager { public int allocateTables(int[] tables, int[] groupSizes, int[] arrivals, int[] departures) { List<Pair<int, int[]>> list = new List<Pair<int,int[]>>(); Array.Sort(tables); for (int i = 0; i < tables.Length; i++) { list.Add(new Pair<int, int[]>(tables[i], new int[200])); } int ret = 0; for (int i = 0; i < arrivals.Length; i++) { bool flag = true; foreach (Pair<int, int[]> p in list) { if (p.Second[arrivals[i]] == 0 && p.First >= groupSizes[i]) { for (int j = arrivals[i]; j < departures[i]; j++) { p.Second[j] = 1; } flag = false; break; } } if (flag) { ret += groupSizes[i]; } } return ret; } }