TheBulgarianWolf

Tom

Mar 6th, 2021
827
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.25 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace Tom
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             int[] priceRatings = Console.ReadLine().Split(" ").Select(int.Parse).ToArray();
  11.             int entryPoint = int.Parse(Console.ReadLine());
  12.             string itemsType = Console.ReadLine();
  13.             int leftElements = 0;
  14.             int rightElements = 0;
  15.             for(int i = 0; i < entryPoint; i++)
  16.             {
  17.                 if(itemsType == "cheap")
  18.                 {
  19.                     if(priceRatings[i] < priceRatings[entryPoint])
  20.                     {
  21.                         leftElements += priceRatings[i];
  22.                     }
  23.                     else
  24.                     {
  25.                         leftElements += 0;
  26.                     }
  27.                 }
  28.                 else
  29.                 {
  30.                     if (priceRatings[i] >= priceRatings[entryPoint])
  31.                     {
  32.                         leftElements += priceRatings[i];
  33.                     }
  34.                     else
  35.                     {
  36.                         leftElements += 0;
  37.                     }
  38.                 }
  39.             }
  40.  
  41.             for(int i = priceRatings.Length - 1; i > entryPoint; i--)
  42.             {
  43.                 if (itemsType == "cheap")
  44.                 {
  45.                     if (priceRatings[i] < priceRatings[entryPoint])
  46.                     {
  47.                         rightElements += priceRatings[i];
  48.                     }
  49.                     else
  50.                     {
  51.                         rightElements += 0;
  52.                     }
  53.                 }
  54.                 else
  55.                 {
  56.                     if (priceRatings[i] >= priceRatings[entryPoint])
  57.                     {
  58.                         rightElements += priceRatings[i];
  59.                     }
  60.                     else
  61.                     {
  62.                         rightElements += 0;
  63.                     }
  64.                 }
  65.             }
  66.  
  67.             if(leftElements >= rightElements)
  68.             {
  69.                 Console.WriteLine("Left - " + leftElements);
  70.             }
  71.             else
  72.             {
  73.                 Console.WriteLine("Right - " + rightElements);
  74.             }
  75.         }
  76.     }
  77. }
Add Comment
Please, Sign In to add comment