Appropriate Partitioning
Tag(s):

## Bitmask, Brute Force, Implementation, Medium-Hard

Problem
Editorial
Analytics

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.

SAMPLE INPUT
3
16 5 14 
SAMPLE OUTPUT
0.125000
Time Limit: 1.0 sec(s) for each input file.
Memory Limit: 256 MB
Source Limit: 1024 KB
Marking Scheme: Marks are awarded when all the testcases pass.
Allowed Languages: C, C++, C++14, Clojure, C#, D, Erlang, F#, Go, Groovy, Haskell, Java, Java 8, JavaScript(Rhino), JavaScript(Node.js), Julia, Kotlin, Lisp, Lisp (SBCL), Lua, Objective-C, OCaml, Octave, Pascal, Perl, PHP, Python, Python 3, R(RScript), Racket, Ruby, Rust, Scala, Swift, Swift-4.1, Visual Basic

## CODE EDITOR

Initializing Code Editor...

## This Problem was Asked in

Challenge Name

{Hack a Heart}()=>love for<code/>;</code>for love;

OTHER PROBLEMS OF THIS CHALLENGE
• Data Structures > Trees
• Math > Combinatorics