Connection Status:
Competition Arena > AlternateColors
SRM 564 · 2012-06-05 · by vexorian · Simulation
Class Name: AlternateColors
Return Type: String
Method Name: getColor
Arg Types: (long long, long long, long long, long long)
Problem Statement

Problem Statement

Bob is playing with his ball destroyer robot. Initially, Bob has r red balls, g green balls and b blue balls. The robot will repeat the following 3-step program until there are no balls left:

  • If there is at least one red ball available, destroy one red ball.
  • If there is at least one green ball available, destroy one green ball.
  • If there is at least one blue ball available, destroy one blue ball.
You are given the longs r, g and b. You are also given a long k. Find the color of the k-th ball (1-index based) that will be destroyed.
  • If the color of the k-th ball to be destroyed is red, return "RED" (quotes for clarity, returned values are case-sensitive).
  • If the color is green, return "GREEN".
  • If the color is blue, return "BLUE".

Constraints

  • r, g and b will each be between 1 and 1000000000000 (10^12), inclusive.
  • k will be between 1 and r+g+b, inclusive.
Examples
0)
1
1
1
3
Returns: "BLUE"

The order in which the balls are destroyed is: Red, green and blue. The third ball was blue.

1)
3
4
5
4
Returns: "RED"

The order in which the balls are destroyed is: Red, green, blue, red, green, blue, red, green, blue, green, blue and blue.

2)
7
7
1
7
Returns: "GREEN"
3)
1000000000000
1
1
1000000000002
Returns: "RED"

Once the only green and blue balls are destroyed, all of the remaining balls will be red.

4)
653
32
1230
556
Returns: "BLUE"

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

Coding Area

Language: C++17 · define a public class AlternateColors with a public method string getColor(long long r, long long g, long long b, long long k) · 198 test cases · 2 s / 256 MB per case

Submitting as anonymous