Connection Status:
Competition Arena > RectangleGroups
SRM 278 · 2005-12-19 · by Vedensky · Brute Force
Class Name: RectangleGroups
Return Type: String
Method Name: maximalIndexed
Arg Types: (vector<string>)
Problem Statement

Problem Statement

You have a list of rectangles divided into groups. The index of a group is the sum of the areas of all the rectangles in the group. You are to determine the group with the biggest index.

You are given a String[] rectangles. Each element of rectangles represents a single rectangle, and is formatted as "G L W", where G is the name of the group to which the rectangle belongs, L is the rectangle's length, and W is the rectangle's width. Return a String formatted as "G I", where G is the name of the group with the maximal index, and I is the index of that group with no leading zeroes. If there are multiple groups with the same maximal index, return the one whose name comes first alphabetically.

Constraints

  • rectangles will contain between 1 and 50 elements, inclusive.
  • Each element of rectangles will be formatted as "G L W", where G is an uppercase letter ('A' - 'Z') and L and W are integers with no leading zeroes.
  • Each L and W will be between 1 and 1000, inclusive.
Examples
0)
{"A 1 2", "A 3 3"}
Returns: "A 11"

There is only one group, and its index is 11 (1*2 + 3*3).

1)
{"A 1 2", "B 3 3", "A 2 1"}
Returns: "B 9"

The index of A is 4, and the index of B is 9.

2)
{"D 1 6", "F 2 3", "G 1 1", "G 5 1", "C 3 2"}
Returns: "C 6"

All groups have the same index, and C comes first alphabetically.

3)
{"S 2 54", "Y 34 65", "F 234 23", "D 84 127", "R 603 46",
"S 36 192", "Y 76 32", "T 54 28", "S 22 22"}
Returns: "R 27738"
4)
{"F 1000 1000"}
Returns: "F 1000000"

Submissions are judged against all 66 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class RectangleGroups with a public method string maximalIndexed(vector<string> rectangles) · 66 test cases · 2 s / 256 MB per case

Submitting as anonymous