TopcoderArchive
SRM2 Dec 2021
SRM 819

DecimalCoins

Problem statement, definition, constraints, and public examples.

Problem Statement

In Absurdistan the coin denominations are powers of ten. More precisely, they have coins worth 10^0, 10^1, 10^2, ..., 10^6 dollars. (That is, 1, 10, 100, ..., 1,000,000 dollars.)

Elisha has some coins in her purse: for each i, she has coins[i] coins worth 10^i dollars each.

Calculate and return the smallest amount of dollars Elisha cannot pay exactly using just the coins in her purse.

Definition

Class:
DecimalCoins
Method:
pay
Parameters:
int[]
Returns:
int
Method signature:
int pay(int[] coins)
(be sure your method is public)

Constraints

  • coins will contain exactly 7 elements.
  • Each element of coins will be between 0 and 1000, inclusive.

Examples

  1. {7, 3, 1, 0, 0, 0, 0}
    Returns: 8
    The coins in Elisha's purse are 1, 1, 1, 1, 1, 1, 1, 10, 10, 10, 100. She can pay any amount between 0 and 7, inclusive, but she cannot pay exactly 8, so that is the smallest amount she cannot pay.
  2. {123, 1, 0, 0, 0, 0, 0}
    Returns: 134
    Elisha's total is 133 dollars, and as most of her money are ones, she can pay each amount between 0 and 133 dollars exactly.
  3. {0, 1, 2, 3, 4, 5, 6}
    Returns: 1
    Elisha has a lot of money, but with no ones she cannot pay the very simple sum of 1 dollar exactly.
  4. {8, 8, 8, 8, 8, 8, 8}
    Returns: 9
  5. {9, 9, 9, 9, 9, 9, 9}
    Returns: 10000000
Back to all problems