CSharp · Console
using System;
public class Program
{
public static int GetMinTime(int n, int[] a, int[] b, int[] c)
{
const int Max = 1000;
if (n < 1 || n > Max)
{
throw new Exception(string.Format("N should be greater than 0 and less than {0}", Max));
}
int[] time = new int[n + 1];
time[0] = 0;
time[1] = a[0];
time[2] = Math.Min(a[0] + a[1], b[0]);
for (int i = 3; i <= n; i++)
{
int tmpMin = Math.Min(
time[i - 1] + a[i - 1],
time[i - 2] + b[i - 2]);
time[i] = Math.Min(
tmpMin,
time[i - 3] + c[i - 3]);
}
return time[n];
}
public static void Main()
{
Console.WriteLine("UniLecs");
var a = new int[] { 5, 2, 5, 20, 20 };
var b = new int[] { 10, 10, 5, 20, 1 };
var c = new int[] { 15, 15, 5, 1, 1 };
Console.WriteLine(string.Format("Answer = {0}", GetMinTime(5, a, b, c))); // 12
var a1 = new int[] { 3, 1 };
var b1 = new int[] { 4, 1 };
var c1 = new int[] { 5, 1 };
Console.WriteLine(string.Format("Answer = {0}", GetMinTime(2, a1, b1, c1))); // 4
}
}