Divide to three
Practice
2.7 (3 votes)
Ad Hoc
Recursion
Implementation
Medium
Math
Problem
79% Success 3504 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code

Stannis borathean is attacking kings landing from three gates.To defend the city Tyrion again comes up with a fair solution. Tyrion has N soldier troops with given strengths. Tyrion wants to divide army into 3 sets such that the sum of strengths in these three sets are as equal as possible. In other words he wants to make three sums \(S1, S2\) and \(S3\) using all troops with constraint that \(S1\)\(S2\)\(S3\) and \(S1\) is as less as possible.

Input
Input contains integer N which is number of troops followed by N lines. Each line contains an integer, strength of one of the troop.

Output
Strength of strongest set that is sum \(S1\).

Constraints:
1N\(12\)
1 ≤ Strength of each troop ≤ \(100\)

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
No similar problems found