Advertisement
simeon_petrov

33. Equal Pairs

Dec 3rd, 2017
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.68 KB | None | 0 0
  1. using System;
  2. using System.Numerics;
  3.  
  4. public class EqualPairs
  5. {
  6.     static void Main()
  7.     {
  8.         BigInteger n = BigInteger.Parse(Console.ReadLine());
  9.         BigInteger pairValue = 0;
  10.         BigInteger pairMaxValue = BigInteger.Parse("-999999999999999999999999999999999999999999999");
  11.         BigInteger pairMinValue = BigInteger.Parse("999999999999999999999999999999999999999999999");
  12.         BigInteger pairDiff = 0;
  13.  
  14.         if (n == 0)
  15.         {
  16.             Console.WriteLine($"Yes, value=0"); return;
  17.         }
  18.  
  19.  
  20.         byte y = 0;
  21.  
  22.         for (BigInteger i = 1; i <= n * 2; i++)
  23.         {
  24.             if (y == 0) // This is the first number in pair
  25.             {
  26.                 pairValue += BigInteger.Parse(Console.ReadLine());
  27.                 y = 1;
  28.                 continue;
  29.             }
  30.  
  31.  
  32.             if (y == 1) // This is the second number in pair
  33.             {
  34.                 pairValue += BigInteger.Parse(Console.ReadLine());
  35.                 if (pairMinValue > pairValue)
  36.                 {
  37.                     pairMinValue = pairValue;
  38.                 }
  39.  
  40.                 if (pairMaxValue < pairValue)
  41.                 {
  42.                     pairMaxValue = pairValue;
  43.                 }
  44.  
  45.                 y = 0;
  46.                 pairValue = 0;
  47.                 continue;
  48.             }
  49.         }
  50.  
  51.         BigInteger diff = pairMaxValue - pairMinValue;
  52.         if (diff < 0)
  53.         {
  54.             diff = diff * -1;
  55.         }
  56.  
  57.         if (pairMinValue == pairMaxValue)
  58.         {
  59.             Console.WriteLine($"Yes, value={pairMaxValue}");
  60.         }
  61.         else
  62.         {
  63.             Console.WriteLine($"No, maxdiff={diff}");
  64.         }
  65.     }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement