Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace HalfSumElement
- {
- class Program
- {
- public static void Main(string[] args)
- {
- int num;
- if (int.TryParse(Console.ReadLine(),out num))
- {
- int [] foo = new int[num];
- for (int i = 0; i < num; i++)
- {
- int value;
- if (int.TryParse(Console.ReadLine(),out value))
- {
- foo[i] = value;
- }
- else
- {
- i--;
- }
- }
- int sum = 0;
- int maxValue =0;
- bool foundEqual = false;
- for (int y = 0; y < foo.Length; y++)
- {
- if(foo[y] > maxValue)
- {
- maxValue = foo[y];
- }
- sum +=foo[y];
- }
- for (int j = 0; j < foo.Length; j++) {
- int number = foo[j];
- if(num * 2 == sum)
- {
- foundEqual = true;
- Console.WriteLine("Yes\n Sum = {0}",sum);
- }
- }
- if(!foundEqual)
- {
- Console.WriteLine("No\n Diff = {0}", Math.Abs(maxValue - (sum- maxValue)));
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment