/* © MATTO MATTI 2017 http://mattomatti.com/pl/a0064 napisane przy użyciu Visual Studio Community 2015 2017-10-22 v 1.0 */ using System; namespace plcode1cs { class Program { static int podajCzas(int[] tab) { if (tab.Length == 1) return tab[0]; if (tab.Length == 2) return tab[1]; int czas = tab[1]; for (int i = 0; i < (tab.Length - 2) / 2; i++) { czas += tab[0]; czas += tab[tab.Length - 1 - i * 2]; czas += tab[1] + tab[1]; } if (tab.Length % 2 == 1) czas += tab[0] + tab[2]; return czas; } static void Main(string[] args) { Console.Write("Podaj ile jest osób:\n n = "); int n = Convert.ToInt32(Console.ReadLine()); int[] tab = new int[n]; Console.WriteLine("Podaj czasy przechodzenia przez most osób (rosnąco):"); for (int i = 0; i < n; i++) tab[i] = Convert.ToInt32(Console.ReadLine()); int w = podajCzas(tab); Console.WriteLine("Osoby mogą przejść w {0} min.", w); Console.ReadKey(); } } }