Guest User

Untitled

a guest
Mar 14th, 2019
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.40 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ConsoleApp5
  8. {
  9.     class Program
  10.     {
  11.         static int[] splitted = { 1, 2, 5, 4, 3, 6, 2 };
  12.         static void Main(string[] args)
  13.         {
  14.             int res = 0;
  15.             for (int i = 0; i < splitted.Count(); i++)
  16.             {
  17.                 var field = check(i);
  18.                 if (field > res)
  19.                 {
  20.                     res = field;
  21.                 }
  22.             }
  23.         }
  24.         static private int check(int i)
  25.         {
  26.             int leftCount = nextLeft(splitted[i], i - 1);
  27.             int rightCount = nextRight(splitted[i], i + 1);
  28.             return (leftCount + 1 + rightCount) * splitted[i];
  29.         }
  30.         static private int nextRight(int value, int i)
  31.         {
  32.             if (i == splitted.Count())
  33.             {
  34.                 return 0;
  35.             }
  36.             if (splitted[i] >= value)
  37.             {
  38.                 return 1 + nextRight(value, i + 1);
  39.             }
  40.             return 0;
  41.         }
  42.        static  private int nextLeft(int value, int i)
  43.         {
  44.             if (i == -1)
  45.             {
  46.                 return 0;
  47.             }
  48.             if (splitted[i] >= value)
  49.             {
  50.                 return 1 + nextLeft(value, i - 1);
  51.             }
  52.             return 0;
  53.         }
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment