Appropriate Partitioning
Practice
4.4 (5 votes)
Implementation
Recruit
Brute Force search
Bitmask
Medium Hard
Ready
Approved
Problem
13% Success 1898 Attempts 50 Points 1s Time Limit 256MB Memory 1024 KB Max Code

Given an array A of integers, choose 2 non-empty disjoint subsets X and Y such that ratio of sum of elements of X and Y is as close to 1 as possible.

Given,

Α : {a1, a2, .... aN}

Find,

X : {x1, x2....xK}

Y : {y1, y2.....yM}

where, X ⊂ A, Y ⊂ A, K > 0 and M > 0 and there does not exist an i, such that ai ∈ X and ai ∈ Y, and Q = abs (1.0 - Σxi / Σyi) is minimum possible. Note that there can exist i and j such that ai ∈ X and aj ∈ Y, i ≠ j but ai = aj.

Output this minimum possible value of Q with precision up to exactly 6 decimal places.

CONSTRAINTS

2 ≤ N ≤ 16
1 ≤ ai ≤ 106, ∀ i ∈ [1, N]

INPUT

The first line of test file contains a single integer N. Next line contains N space separated integers representing the array A.

OUTPUT

Print in a single line, the value of Q with exactly 6 decimal places.

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
17 votes
Tags:
EasyImplementationMathProbabilityStatistics
Points:50
17 votes
Tags:
Data StructuresTreeApprovedMedium-HardSegment tree
Points:20
32 votes
Tags:
ApprovedCombinatoricsEasyImplementationMathOpen