TopcoderArchive
Archive
Algorithm problem

CuttingCake

Problem statement, definition, constraints, and public examples.

Problem Statement

Farmer John and Cow Brus received a cake. The weight of the cake was total.

They divided the cake into N pieces. Obviously, the total weight of these pieces must be total. Additionally, you have the following information:
  • The weight of each piece was at least w.
  • You are given a String[] compare. If the j-th character of the i-th element of compare is 'Y', the weight of the j-th piece was more than or equal to the weight of the i-th piece. Otherwise, you have no information about weights of these pieces.

You are given a String name. The i-th character of this String is either 'J' or 'B', and shows who ate the i-th piece ('J' stands for John, and 'B' stands for Brus). Return the minimal possible weight of Cake John ate.

Definition

Class:
CuttingCake
Method:
minimalWeight
Parameters:
int, int, String, String[]
Returns:
double
Method signature:
double minimalWeight(int total, int w, String name, String[] compare)
(be sure your method is public)

Constraints

  • total will be between 2 and 50,000, inclusive.
  • w will be between 1 and 1,000, inclusive.
  • name will contain between 2 and 40 characters, inclusive.
  • Each character in name will be either 'J' or 'B'.
  • compare will contain exactly N elements, where N is the number of characters of name.
  • Each element of compare will contain exactly N characters, where N is the number of characters of name.
  • Each character in compare will be either 'Y' or 'N'.
  • For each i, the i-th character of the i-th element of compare will be 'N'.
  • total will be at least N * w.

Examples

    No public sample cases were explicitly marked for this problem in the original data.

    Back to all problems