TopCoder SRM 156 DIV 1 Medium 練習

問題

いつ、どこから、どこまでエレベータを利用するかという情報が与えられるから、エレベータが最善の動きをしたときに全員を運び終えるまでにかかる時間はどれくらいですか。

人が全部で5人(!)しか居ないから全部試す。

using System;
using System.Text;
using System.Text.RegularExpressions;
using System.Collections;
using System.Collections.Generic;

public class SmartElevator {
    int[] arr, stt, dest;

    public int timeWaiting(int[] arrivalTime, int[] startingFloor, int[] destinationFloor) {
        arr = arrivalTime;
        stt = startingFloor;
        dest = destinationFloor;
        return rec(1, 0, new bool[arr.Length], new bool[arr.Length]);
    }

    private int rec(int floor, int time, bool[] arrived, bool[] cmpl)
    {
        int res = int.MaxValue;
        for (int i = 0; i < arrived.Length; ++i)
        {
            if (!cmpl[i])
                if (!arrived[i])
                {
                    arrived[i] = true;
                    res = Math.Min(res, rec(stt[i], Math.Max(arr[i], time + Math.Abs(floor - stt[i])), arrived, cmpl));
                    arrived[i] = false;
                }
                else
                {
                    cmpl[i] = true;
                    res = Math.Min(res, rec(dest[i], time + Math.Abs(floor - dest[i]), arrived, cmpl));
                    cmpl[i] = false;
                }
        }
        return res == int.MaxValue ? time : res;
    }
}