j0nze

half sum element

Nov 4th, 2017
490
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.13 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 _10_Half_Sum_Element
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int n = int.Parse(Console.ReadLine());
  14.  
  15.             int currentMax = int.Parse(Console.ReadLine());
  16.             int totalSum = 0;
  17.  
  18.             for (int i = 0; i < n-1; i ++)
  19.             {
  20.                 int num = int.Parse(Console.ReadLine());
  21.  
  22.                 if (num > currentMax)
  23.                 {
  24.                     totalSum = totalSum + currentMax;
  25.                     currentMax = num;
  26.                 }
  27.                 else
  28.                 {
  29.                     totalSum = totalSum + num;
  30.                 }
  31.             }
  32.             if (currentMax == totalSum)
  33.             {
  34.                 Console.WriteLine("Yes");
  35.                 Console.WriteLine("Sum = {0}", totalSum);
  36.             }
  37.             else
  38.             {
  39.                 Console.WriteLine("No");
  40.                 Console.WriteLine("Diff = {0}", Math.Abs(totalSum - currentMax));
  41.             }
  42.         }
  43.     }
  44. }
Add Comment
Please, Sign In to add comment