TopcoderArchiveVisit Topcoder
Archive
Algorithm problem

Multiplier

Problem statement, definition, constraints, and public examples.

Problem Statement

The "Multiplier Effect" in Economics refers to the fact that when the government spends money, the governmental expenditure triggers additional spending. The idea is that the initial expenditure becomes income to the recipients of the money, and they in turn spend some fraction of this additional income. This additional spending once again becomes new income and generates more spending.

We want to apply this principle to our economy, modeled as having two sectors, services and goods. We have data for each sector telling what percent of additional income is spent on services and what percent is spent on goods.

Each expenditure is treated as a separate quantity, and the two expenditures that are triggered by an earlier expenditure are each reduced to whole dollar amounts -- any fractional amount is saved (not spent). In other words, when a percentage is used to calculate derived spending, the amount is immediately rounded down to the nearest integer before being used in any other calculations.

Let amount be an initial externally generated expenditure on goods. Create a class Multiplier that contains a method spending that takes as input the int amount and int[] percent, the four spending percentages. The method returns the total additional spending generated by amount (but not including amount).

percent will contain four integers in the following order:

  • percent of income received by the goods sector that is spent on goods
  • percent of income received by the goods sector that is spent on services
  • percent of income received by the services sector that is spent on goods
  • percent of income received by the services sector that is spent on services

Definition

Class:
Multiplier
Method:
spending
Parameters:
int, int[]
Returns:
int
Method signature:
int spending(int amount, int[] percent)
(be sure your method is public)

Constraints

  • amount will be between 0 and 100,000 inclusive
  • percent will have exactly 4 elements
  • each element in percent will be between 0 and 95 inclusive
  • the sum of the first two elements in percent will be no greater than 95
  • the sum of the last two elements in percent will be no greater than 95

Examples

  1. 23
    {20,50,10,40}
    Returns: 23
    23G 4G 11S 0G 2S 1G 4S 0G 0S 0G 1S This tree shows the 23 received by Goods at the top. This results in expenditures of 4 (20% of 23) received by Goods and 11 (50% of 23) received by Services. The 4 received by Goods results in an expenditure of 2 (50% of 4) on services which results in 0 additional expenditure. The 11 received by services results in expenditures of 1 (10% of 11) and 4 (40% of 11) and the 4 received by Services resulted in spending of 1 (40% of 4). The sum of all the expenditures (not including the initial 23) is 4 + 2 + 11 + 1 + 4 + 1 = 23.
  2. 100000
    {35,60,70,25}
    Returns: 1026091
  3. 5
    {19,19,19,19}
    Returns: 0
    No additional spending is generated since 19% of 5 is less than 1.
Back to all problems