Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections;
- using System.Linq;
- public class Program
- {
- public static void Main()
- {
- int[] numbers = Console.ReadLine()
- .Split()
- .Select(a => Math.Abs(int.Parse(a)))
- .Where(n => n != 0)
- .ToArray();
- int max = numbers.Sum();
- bool result = max >= 13;
- int total = max * 2 + 1;
- BitArray prev = new BitArray(total);
- BitArray current = new BitArray(total);
- prev[max] = true;// zero
- foreach (var currentNum in numbers)
- {
- current.SetAll(false);
- for (int i = 0; i < prev.Length; i++)
- {
- if (prev.Get(i))
- {
- current.Set(i - currentNum, true);
- current.Set(i + currentNum, true);
- }
- }
- prev.SetAll(false);
- prev.Or(current);
- }
- result = result && prev.Get(max + 13); // short circuits to false if sum less than 13
- Console.WriteLine(result ? "Yes" : "No");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement