Advertisement
ramsess

Untitled

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