Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace EqualPairs
- {
- class EqualPairs
- {
- static void Main(string[] args)
- {
- int chisloto = int.Parse(Console.ReadLine());
- int counter = 0;
- var sum = 0;
- var currentSum = 0;
- var biggestDiff = 0;
- bool equalSums = true;
- bool haveASum = false; //flag
- for(int i = 0; i < chisloto * 2; i++)
- {
- if (counter < 2)
- {
- int number = int.Parse(Console.ReadLine());
- currentSum += number;
- counter++;
- }
- if(haveASum)
- {
- if(sum != currentSum && counter == 2)
- {
- equalSums = false;
- var difference = Math.Abs(sum - currentSum);
- if(biggestDiff < difference)
- {
- biggestDiff = difference;
- }
- sum = currentSum;
- currentSum = 0;
- }
- else if(counter == 2)
- {
- sum = currentSum;
- currentSum = 0;
- }
- }
- else if(counter == 2 && !haveASum)
- {
- haveASum = true;
- sum = currentSum;
- currentSum = 0;
- }
- if(counter == 2)
- {
- counter = 0;
- }
- }
- if(equalSums)
- {
- Console.WriteLine("Yes, value={0}" , sum);
- }
- else
- {
- Console.WriteLine("No, maxdiff={0}" , biggestDiff);
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment