EqualTowers
SRM 442 · 2009-06-13 · by mateuszek
Problem Statement
Johnny has some number of rectangular bricks. He can put bricks on top of each other to build a tower. He wishes to build two towers of equal height out of his bricks (each tower must contain at least one brick). He also wants the towers to be as tall as possible. Note that Johnny doesn't have to use all the bricks.
You are given a
Constraints
- bricks will contain between 1 and 50 elements, inclusive.
- Each element of bricks will be between 1 and 500000, inclusive.
- The sum of all elements of bricks will not be greater than 500000.
{ 2, 3, 5 }
Returns: 5
Johnny can build two towers of height 5. One contains a single brick of height 5, and the other contains a brick of height 2 and a brick of height 3.
{ 10, 9, 2 }
Returns: -1
There's nothing Johnny can do here.
{ 11, 11 }
Returns: 11
{ 88242, 313, 1991, 4207, 2483, 1763, 224, 16, 582, 22943, 28632, 47682, 378, 90, 88, 43, 117, 19, 8 }
Returns: 99901
{ 188242, 313, 1991, 4207, 2483, 1763, 224, 16, 582, 22943, 111653, 23787, 16820, 12415, 1270, 3032, 2293, 5221, 396, 42 }
Returns: 199661
Submissions are judged against all 91 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class EqualTowers with a public method int height(vector<int> bricks) · 91 test cases · 2 s / 256 MB per case