using System;
class Program
{
static void Main()
{
int[] arr = {3, 2, 7, 10};
Console.WriteLine("Maximum sum of array 1 is {0}", FindMaxSum(arr));
int[] arr2 = {3, 2, 5, 10, 7};
Console.WriteLine("Maximum sum of array 2 is {0}", FindMaxSum(arr2));
Console.ReadKey();
}
static int FindMaxSum(int[] arr)
{
int n = arr.Length;
int incl = arr[0];
int excl = 0;
int excl_new;
for (int i = 1; i < n; i++)
{
/* current max excluding i */
excl_new = Math.Max(incl, excl);
/* current max including i */
incl = excl + arr[i];
excl = excl_new;
}
/* return max of incl and excl */
return Math.Max(incl, excl);
}
}