Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- class HalfSum
- {
- static void Main()
- {
- long n = long.Parse(Console.ReadLine());
- //declare an array storing all entered values
- long[] enteredValues = new long[2*n];
- //fill in the array propting the user for values
- for (long i = 0; i < 2*n; i++)
- {
- enteredValues[i] = long.Parse(Console.ReadLine());
- }
- //declare 2 new arrays. One for the first half of of the enteredValues array and another for the second half
- long[] leftSide = enteredValues.Take(enteredValues.Length / 2).ToArray();
- long[] rightSide = enteredValues.Skip(enteredValues.Length / 2).ToArray();
- long leftSideSum = leftSide.Sum();
- long rightSideSum = rightSide.Sum();
- if (leftSideSum == rightSideSum)
- {
- Console.WriteLine("Yes, sum=" + leftSideSum);
- }
- else if (leftSideSum > rightSideSum)
- {
- Console.WriteLine("No, diff=" + (leftSideSum-rightSideSum));
- }
- else
- {
- Console.WriteLine("No, diff=" + (rightSideSum-leftSideSum));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement