Largest sum contiguous subarray


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;

namespace OneCompiler
{
	public class Program
	{
		public static void Main(string[] args)
		{
			int n = int.Parse(Console.ReadLine());
			
			int[] arr = Array.ConvertAll(Console.ReadLine().Split(" "), new Converter<string,int>(StringToInteger));
			
			var maxSum = MaximumSum(arr);
			
			Console.WriteLine(maxSum);
		}
		
		private static int StringToInteger(string s)
		{
		  return int.Parse(s);
		}
		
		private static int MaximumSum(int[] arr)
		{
		  int n = arr.Length;
		  
		  if (n == 0)
		  {
		    return 0;
		  }
		  else if (n == 1)
		  {
		    return arr[0];
		  }
		  else
		  {
		    var maxSum = int.MinValue;
		    var currSum = 0;
		    
		    for (int i = 0; i < n; i++)
		    {
		      currSum += arr[i];
		      maxSum = Math.Max(maxSum, currSum);
		      
		      if (currSum < 0)
		      {
		        currSum = 0;
		      }
		    }
		    
		    return maxSum;
		  }
		}
	}
}