Skip to content

meerrec/Array-Partitioning

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 

Repository files navigation

Array Partitioning

Divide a given array of numbers into two subarrays such that the absolute difference between their sums is the smallest possible. For example, the array [2, 5, 4, 7, 15, 20] can be divided into subarrays [15, 7, 4] and [20, 5, 2]. The difference between the sums of those arrays is 1, and it is the smallest.

The first line of the input contains the size of the array. The next line contains the array elements. Print the subarrays and the difference of their sums.

For example:

Input:

6

4, 15, 20, 2, 7, 5

Output:

[15, 7, 4]

[20, 5, 2]

1

(The sum of the first subarray is 26, the sum of the second subarray is 27, the difference is 1.)

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published