TopcoderArchive
Archive
Algorithm problem

RecordingArtistRoyalties

Problem statement, definition, constraints, and public examples.

Problem Statement

Recording artist royalties for commercial music albums are sometimes paid as a percentage of the album's wholesale price. First, a packaging percentage is subtracted from the wholesale price of the album (since it is paid for by the record company). Then, a percentage of the remaining price is set aside for artist royalties. This amount is multiplied by the number of units sold. However, the record company usually gives the artist cash advances during the recording process (for studio time, equipment, etc...). These advances must be recouped by the record company before any royalties are paid out. Also, wholesale prices vary among different sales channels - for example, record clubs will typically get the album at a lower wholesale price than retail stores. Given the wholesale price (formatted as "$XX.XX", where each X is a single digit) and number of units sold for each sales channel, the packaging percentage, the royalty percentage, and the advances given by the record company (in dollars), determine how much the recording artist will earn in royalties. Return this value as a double representing the number of dollars earned by the artist. If the royalty total after subtracting advances is negative, return 0. The wholesale prices and sales figures for the various sales channels will be given in the String[] prices and the int[] unitsSold. Element i of prices and element i of unitsSold represent the wholesale price and sales reported by the ith sales channel. See the examples for a more detailed explanation.

Definition

Class:
RecordingArtistRoyalties
Method:
royalties
Parameters:
String[], int[], int, int
Returns:
double
Method signature:
double royalties(String[] prices, int[] unitsSold, int royaltyPercentage, int advances)
(be sure your method is public)

Notes

  • The return value must have an absolute or relative error of 1e-9.

Constraints

  • prices will contain between 1 and 10 elements, inclusive.
  • Each element of prices will be formatted as "$XX.XX", where each X is a single digit ('0'-'9'). There will be exactly two digits on both sides of the decimal point.
  • unitsSold will contain the same number of elements as prices.
  • Each element of unitsSold will be between 0 and 1000000, inclusive.
  • royaltyPercentage will be between 1 and 50, inclusive.
  • advances will be between 0 and 500000, inclusive.

Examples

  1. {"$09.00", "$12.00"}
    {5000, 90000}
    15
    100000
    Returns: 68750.0
    There are two sales channels - one receives the album at a wholesale price of $9.00 and sells 5000 copies, and the other receives the album at a wholesale price of $12.00 and sells 90,000 copies. 15% of (9*5000 + 12*90,000) is $168,750. The record company must recoup $100,000 in advances, so that amount is subtracted from the total given to the artist.
  2. {"$00.99", "$49.99", "$09.99"}
    {10099, 50000, 500}
    20
    0
    Returns: 502898.602
    The artist is owed approximately $502,898.60.
  3. {"$19.71"}
    {9000}
    50
    100000
    Returns: 0.0
    Even with a 50% royalty rate, this artist will remain in debt to the record company because of the $100,000 advance.
  4. {"$99.99", "$00.00"}
    {0, 1000000}
    15
    0
    Returns: 0.0
Back to all problems