#K62222. Equal Partition of Array

    ID: 31484 Type: Default 1000ms 256MiB

Equal Partition of Array

Equal Partition of Array

You are given an array \(B\) of integers. Your task is to determine whether it is possible to partition the array into two non-empty subsequences such that the sum of the elements in each subsequence is equal.

The problem can be formally defined as follows:

Given an array \(B = [b_1, b_2, \dots, b_n]\), check if there exist two non-empty disjoint subsets \(S_1\) and \(S_2\) satisfying \(S_1 \cup S_2 = \{1, 2, \dots, n\}\) and

[ \sum_{i \in S_1} b_i = \sum_{j \in S_2} b_j ]

Print YES if such a partition exists, otherwise print NO.

Note: The input will first give an integer \(N\) representing the number of elements in the array, followed by \(N\) space-separated integers for the array.

inputFormat

The input consists of two lines:

  • The first line contains a single integer \(N\), the number of elements in the array.
  • The second line contains \(N\) space-separated integers representing the elements of the array \(B\).

outputFormat

Output a single line containing either YES if the array can be partitioned into two non-empty subsequences with equal sums, or NO otherwise.

## sample
4
1 5 11 5
YES