.NET Fiddle

CSharp · Console

/Program.cs

using System;
using System.Collections.Generic;
					
public class Program
{
	public void Main()
	{
            Console.WriteLine(f(new List<int>{1,  1,  4,  2,  0}));
            Console.WriteLine(f(new List<int>{2,  2,  2,  2,  2}));
            Console.WriteLine(f(new List<int>{0,  6,  0,  6,  0}));
            Console.WriteLine(f(new List<int>{12, 5,  3,  2,  1}));
            Console.WriteLine(f(new List<int>{1,  14, 14, 3,  2}));
            Console.WriteLine(f(new List<int>{0,  0,  1,  0,  50}));
	}
	
	int f(List<int>p){p.Sort();p[3]--;p[4]--;return p[2]-->0?1+f(p):0;}
}
;