#108. 数组分割求和

    ID: 108 Type: Default 1000ms 256MiB Tried: 0 Accepted: 0 Difficulty: (None) Uploaded By: Tags>codingbatArray-3gesp5前缀和一维数组

数组分割求和

Array Split Sum

Background

Congcong is playing a number game. He has an array of integers and wants to know if he can split this array into two parts such that the sum of numbers in both parts is equal.

Problem Description

Given a non-empty array of integers, return true if there is a place to split the array so that the sum of the numbers on one side is equal to the sum of the numbers on the other side. Otherwise, return false.

Input Format

Input is given from standard input in the following format.

A non-empty array of integers, with elements separated by spaces.

Output Format

Output is printed to standard output in the following format.

Output true if such a split point exists; otherwise, output false.

Sample

[1 1 1 2 1]
true
[2 1 1 2 1]
false
[10 10]
true

Sample Explanation

Sample 1: The array is [1 1 1 2 1]. The total sum is 66. It can be split after the third 11, resulting in [1 1 1] and [2 1]. Both parts sum to 33. Thus, return true.

Sample 2: The array is [2 1 1 2 1]. The total sum is 77. No split point can make both parts sum equally. Thus, return false.

Sample 3: The array is [10 10]. The total sum is 2020. It can be split after the first 1010, resulting in [10] and [10]. Both parts sum to 1010. Thus, return true.

Constraints

Time limit for each test case is 11 second, memory limit is 10241024 KiB.