using System;
using System.Collections.Generic;
namespace App
{
class Program
{
static void Main(string[] args)
{
int n;//size of array
Console.Write("Enter size of array: ");
n = int.Parse(Console.ReadLine());
int[] a = new int[n];
for (int i = 0; i < n; i++)
{
Console.Write("Enter element of array {0}: ",(i+1));
a[i] = int.Parse(Console.ReadLine());
}
int minCost = int.MaxValue;
Console.Write("Enter k: ");
int k = int.Parse(Console.ReadLine());
if (n == 1)
{
Console.WriteLine("Minimum cost: {0}", a[0]);
return;
}
for (int i = 0; i < n - 1; i++)
{
if (k * (a[i] + a[i + 1]) < minCost) {
minCost = k * (a[i] + a[i + 1]);
}
}
Console.WriteLine("Minimum cost: {0}", minCost);
Console.ReadLine();
}
}
}
Comments
Leave a comment