WindFell

Untitled

Feb 7th, 2018
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.93 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 Half_Sum_Element
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             var n = int.Parse(Console.ReadLine());
  14.             var max = 0;
  15.             var sum = 0;
  16.             for (int i = 0; i < n; i++)
  17.             {
  18.                 var number = int.Parse(Console.ReadLine());
  19.                 sum += number;
  20.                 if (number > max)
  21.                 {
  22.                     max = number;
  23.                 }
  24.             }
  25.             if (max == sum - max)
  26.             {
  27.                 Console.WriteLine("Yes");
  28.                 Console.WriteLine($"Sum = {max}");
  29.             }
  30.             else
  31.             {
  32.                 Console.WriteLine("No");
  33.                 Console.WriteLine($"Diff = {Math.Abs(sum - 2 * max)}");
  34.             }
  35.         }
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment