WindFell

EqualPairs

Feb 8th, 2018
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.18 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 Equal_Pairs
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             var n = int.Parse(Console.ReadLine());
  14.             var first = int.Parse(Console.ReadLine());
  15.             var second = int.Parse(Console.ReadLine());
  16.             var sum = first + second;
  17.             var maxDiff = int.MinValue;
  18.  
  19.             for (int i = 0; i < n - 1; i++)
  20.             {
  21.                 var a = int.Parse(Console.ReadLine());
  22.                 var b = int.Parse(Console.ReadLine());
  23.                 if (sum != a + b)
  24.                 {
  25.                     var diff = Math.Abs(sum - (a + b));
  26.                     if (maxDiff < diff)
  27.                     {
  28.                         maxDiff = diff;
  29.                     }
  30.                     sum = a + b;
  31.                 }
  32.             }
  33.             if (maxDiff == int.MinValue)
  34.             {
  35.                 Console.WriteLine($"Yes, value={sum}");
  36.             }
  37.             else
  38.             {
  39.                 Console.WriteLine($"No, maxdiff={maxDiff}");
  40.             }
  41.         }
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment