Advertisement
anizko

02. Half Sum Element

Apr 10th, 2019
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.00 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Half_Sum_Element
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int countNum = int.Parse(Console.ReadLine());
  10.             int max = int.MinValue;
  11.             int total = 0;
  12.  
  13.             for(int i=1;i<= countNum;i++)
  14.             {
  15.                 int Num = int.Parse(Console.ReadLine());
  16.                 if(Num>max)
  17.                 {
  18.                     max = Num;
  19.                     total += Num;
  20.                 }
  21.                 else
  22.                 {
  23.                     total += Num;
  24.                 }
  25.             }
  26.             if(total-max==max)
  27.             {
  28.                 Console.WriteLine("Yes");
  29.                 Console.WriteLine($"Sum = {max}");
  30.             }
  31.             else
  32.             {
  33.                 int diff = Math.Abs(max - (total - max));
  34.                 Console.WriteLine("No");
  35.                 Console.WriteLine($"Diff = {diff}");
  36.             }
  37.  
  38.  
  39.  
  40.  
  41.  
  42.            
  43.         }
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement