Problem Statement
Inspired by the Dire Straits song, "Money for Nothing", you have decided to become a rock star. After a lengthy recording session, you have acquired:
Unfortunately, your record company has placed several restrictions on your album:
Given ints ff, fs, sf, and ss, representing the quantities described above, return the maximum number of songs that can be placed on a single album without violating the record company's restrictions.
- a total of ff songs that start fast and end fast,
- a total of fs songs that start fast and end slow,
- a total of sf songs that start slow and end fast, and
- a total of ss songs that start slow and end slow.
Unfortunately, your record company has placed several restrictions on your album:
- 1. A song that ends fast may only be immediately followed by a song that starts fast.
- 2. A song that ends slow may only be immediately followed by a song that starts slow.
- 3. If you have at least one song that starts fast, then the first song on the album must start fast. Otherwise, this restriction can be ignored.
Given ints ff, fs, sf, and ss, representing the quantities described above, return the maximum number of songs that can be placed on a single album without violating the record company's restrictions.
Definition
- Class:
- RockStar
- Method:
- getNumSongs
- Parameters:
- int, int, int, int
- Returns:
- int
- Method signature:
- int getNumSongs(int ff, int fs, int sf, int ss)
- (be sure your method is public)
Constraints
- ff, fs, sf, and ss will each be between 0 and 1000 inclusive.
- At least one of ff, fs, sf or ss will be greater than 0.
Examples
100
0
0
200
Returns: 100
You must begin the album with one of your fast songs by the 3rd restriction. By the 1st restriction, each subsequent song must also now start fast.0
0
20
200
Returns: 201
Since you do not have any songs that start fast, you may begin the album with a song that starts slow. You can use 201 songs by first using the 200 songs that start slow and end slow, then finishing the album with one song that starts slow and ends fast.1
2
1
1
Returns: 5
192
279
971
249
Returns: 999