#K1591. Equal Subset Sum Partition
Equal Subset Sum Partition
Equal Subset Sum Partition
You are given a list of n integers. Your task is to determine whether the list can be partitioned into two subsets such that the sum of the elements in both subsets is equal.
In mathematical terms, let \( S \) be the sum of all elements. The problem is solvable if and only if \( S \) is even, i.e., \( S = 2K \) for some integer \( K \), and there exists a subset whose sum is exactly \( K \).
You need to design an algorithm that reads the input from stdin
and prints the result to stdout
. Print True
if such a partition exists, otherwise print False
.
inputFormat
The input is given in two lines:
- The first line contains a single integer \( n \), the number of elements in the list.
- The second line contains \( n \) space-separated integers representing the elements of the list.
You should read from stdin
.
outputFormat
Output a single line with either True
if the list can be partitioned into two subsets with equal sum, or False
otherwise. Write the output to stdout
.
4
1 5 11 5
True