Yachkov

Half sum element

Feb 4th, 2021
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.21 KB | None | 0 0
  1. using System;
  2. using System.ComponentModel;
  3. using System.ComponentModel.DataAnnotations;
  4. using System.ComponentModel.Design;
  5. using System.Globalization;
  6. using System.Net.Http.Headers;
  7. using System.Reflection;
  8. using System.Runtime.ConstrainedExecution;
  9. using System.Security.Cryptography;
  10.  
  11.  
  12. namespace SomeExcercises
  13. {
  14.     class Program
  15.     {
  16.         static void Main(string[] args)
  17.         {
  18.             int n = int.Parse(Console.ReadLine());
  19.             int sum = 0;
  20.             int max = int.MinValue;
  21.  
  22.             for (int i = 0; i < n; i++)
  23.             {
  24.                 int num = int.Parse(Console.ReadLine());
  25.                 sum += num;
  26.                 if (num > max)
  27.                 {
  28.                     max = num;
  29.                 }
  30.             }
  31.             int sumWithoutMaxNumber = sum - max;
  32.             if (max == sumWithoutMaxNumber)
  33.             {
  34.                 Console.WriteLine("Yes");
  35.                 Console.WriteLine($"Sum = {max}");
  36.             }
  37.             else
  38.             {
  39.                 int diff = Math.Abs(max - sumWithoutMaxNumber);
  40.                 Console.WriteLine("No");
  41.                 Console.WriteLine($"Diff = {diff}");
  42.  
  43.             }
  44.  
  45.         }
  46.     }
  47. }
  48.  
  49.  
  50.  
  51.  
Advertisement
Add Comment
Please, Sign In to add comment