nicolepavlova386

Half_Sum_Element

Oct 4th, 2016
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.90 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.             int sum = 0;
  15.             int maxN = 0;
  16.  
  17.  
  18.             for (int i = 0; i < n; i++)
  19.             {
  20.                 int number = int.Parse(Console.ReadLine());
  21.                 maxN = Math.Max(number, maxN);
  22.  
  23.                 sum = number + sum;
  24.             }
  25.             if (sum - maxN == maxN)
  26.             {
  27.                 Console.WriteLine("Yes");
  28.                 Console.WriteLine("Sum = {0}", sum / 2);
  29.             }
  30.             else
  31.             {
  32.                 Console.WriteLine("No");
  33.                 Console.WriteLine("Diff = {0}", Math.Abs(maxN - (sum - maxN)));
  34.             }
  35.         }
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment