ChangingSounds
SRM 366 · 2007-09-18 · by jthread
Problem Statement
You are a guitar player and you are going to play a concert. You don't like to play all the songs at the same volume, so you decide to change the volume level of your guitar before each new song. Before the concert begins, you make a list of the number of intervals you will be changing your volume level by before each song. For each volume change, you will decide whether to add that number of intervals to the volume, or substract it.
You are given a
Constraints
- changeIntervals will contain between 1 and 50 elements, inclusive.
- Each element of changeIntervals will be between 1 and maxLevel, inclusive.
- maxLevel will be between 1 and 1000, inclusive.
- beginLevel will be between 0 and maxLevel, inclusive.
{5, 3, 7}
5
10
Returns: 10
First we turn the volume down to 0 (-5), then we turn it up to 3 (+3), and then up to 10 (+7) for the last song.
{15, 2, 9, 10}
8
20
Returns: -1
Adding 15 to 8 or substracting 15 from 8 both give an invalid sound level.
{74,39,127,95,63,140,99,96,154,18,137,162,14,88}
40
243
Returns: 238
{214,40,203,333,118,575,217,386,319,548,137,34,415,473,140,309,333,314,358,17,330,301,188,241,542,49,226,65,423,452,288,369,281,288,485,460,506,636,520,262,489,493,405,227,507,384,544,666,118,582}
367
1000
Returns: 999
{483,430,157,657,360,424,446,481,2,531,360,154,234,22,492,633,244,338,393,125,298,386,448,211,624,602,60,43,109,341,483,582,280,503,444,277,645,247,186,233,86,530,264,208,466,65,471,644,210,330}
551
1000
Returns: 999
Submissions are judged against all 119 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class ChangingSounds with a public method int maxFinal(vector<int> changeIntervals, int beginLevel, int maxLevel) · 119 test cases · 2 s / 256 MB per case