#K15226. Equal Subset Partition

    ID: 24310 Type: Default 1000ms 256MiB

Equal Subset Partition

Equal Subset Partition

You are given a list of integers. Your task is to determine whether this list can be partitioned into two subsets such that the sum of the elements in both subsets is equal. If such a partition exists, output 1; otherwise, output 0.

The solution involves checking if the total sum of the array is even; if not, the partition is impossible. Otherwise, we use a dynamic programming approach to determine if there exists a subset with a sum equal to half of the total sum. All operations are to be performed using standard input and output.

Note: The ordering of the integers does not matter, and each number can only be used once.

inputFormat

The input is given on the standard input in the following format:

  1. An integer N representing the number of elements in the array.
  2. N space-separated integers representing the array elements.

outputFormat

Output a single integer. Print 1 if the array can be partitioned into two subsets with equal sum, otherwise print 0. The output should be written to the standard output.

## sample
4
1 5 11 5
1

</p>