Advertisement
Guest User

HalfSumEdited

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