TopCoder problem "Medici" used in SRM 204 (Division II Level One)



Problem Statement

    

In the new boardgame Medici, you play an aristocrat in 15th-century Florence. On each turn, you gather points in three categories: fame, fortune, and dirty secrets with which you can blackmail other players. The winner is the player with the most points in his weakest category at the end of the game. For example, suppose there are three players with the following points:

    NAME       FAME  FORTUNE  SECRETS
    ---------------------------------
    Salvestro   20      60       40
    Giovanni    30      80       30
    Cosimo      50      40       50
Salvestro's weakest category is Fame, in which he has 20 points. Giovanni's weakest categories are Fame and Secrets, with 30 points in both. Cosimo's weakest category is Fortune, with 40 points. Cosimo is the winner.

You will be given three int[]s, fame, fortune, and secrets. The points for player i are given as the i-th elements of the three int[]s. You are to return the (zero-based) index of the winning player. If there is a tie for the winning score, the game is declared a draw and replayed, in which case you should return -1.

 

Definition

    
Class:Medici
Method:winner
Parameters:int[], int[], int[]
Returns:int
Method signature:int winner(int[] fame, int[] fortune, int[] secrets)
(be sure your method is public)
    
 

Constraints

-fame contains between 2 and 20 elements, inclusive.
-fortune and secrets each contain the same number of elements as fame.
-All elements of fame, fortune, and secrets are between 0 and 100, inclusive.
 

Examples

0)
    
{ 20, 30, 50 }
{ 60, 80, 40 }
{ 40, 30, 50 }
Returns: 2
The example above. Salvestro is player 0, Giovanni is player 1, and Cosimo is player 2.
1)
    
{   0, 100, 100, 100 }
{ 100,   0, 100,  50 }
{  50,  50,  50, 100 }
Returns: -1
Players 2 and 3 both have 50 points in their weakest categories (Secrets and Fortune, respectively). The game is a draw.
2)
    
{ 1, 0 }
{ 1, 99 }
{ 1, 99 }
Returns: 0
Player 0 wins even though he scored 195 fewer total points than player 1. Total points is irrelevant in determining the winner.
3)
    
{ 39, 42, 57 }
{ 42, 39, 57 }
{ 57, 39, 42 }
Returns: 2
Players 0 and 1 tie for second place, but that does not cause the game to be declared a draw.
4)
    
{ 3, 98, 0, 71, 81, 85, 99, 58, 93, 79, 100, 98, 73, 83, 52, 100, 37, 93, 39, 27 }
{ 96, 34, 45, 20, 72, 71, 7, 18, 47, 35, 54, 51, 52, 21, 49, 20, 44, 72, 90, 93 }
{ 15, 72, 50, 84, 41, 49, 35, 71, 20, 29, 73, 18, 35, 61, 70, 34, 59, 68, 90, 18 }
Returns: 17

Problem url:

http://www.topcoder.com/stat?c=problem_statement&pm=2916

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=5850&pm=2916

Writer:

vorthys

Testers:

lbackstrom , brett1479

Problem categories:

Simple Search, Iteration, Simulation