GUMIAndSongsDiv2
SRM 588 · 2013-06-25 · by semiexp
Problem Statement
You are given a
Gumi finds it difficult to sing songs with quite different tones consecutively. You are given a
You are also given an
Constraints
- duration and tone will each contain between 1 and 15 elements, inclusive.
- duration and tone will contain the same number of elements.
- Each element of duration will be between 1 and 100,000, inclusive.
- Each element of tone will be between 1 and 100,000, inclusive.
- T will be between 1 and 10,000,000, inclusive.
{3, 5, 4, 11}
{2, 1, 3, 1}
17
Returns: 3
There are four songs. Two songs have tone 1 and their durations are 5 and 11, respectively. One song has tone 2 and its duration is 3. One song has tone 3 and its duration is 4. Gumi has 17 units of time to sing. It is impossible for Gumi to sing all four songs she knows within the given time: even without the breaks the total length of all songs exceeds 17. Here is one way how she can sing three songs: First, she sings song 0 in 3 units of time. Second, she waits for |2-3|=1 unit of time and then sings song 2 in 4 units of time. Finally, she waits for |3-1|=2 units of time and then sings song 1 in 5 units of time. The total time spent is 3+1+4+2+5 = 15 units of time.
{100, 200, 300}
{1, 2, 3}
10
Returns: 0
In this case, T is so small that she can't sing at all.
{1, 2, 3, 4}
{1, 1, 1, 1}
100
Returns: 4
There is plenty of time, so she can sing all 4 songs.
{10, 10, 10}
{58, 58, 58}
30
Returns: 3
{8, 11, 7, 15, 9, 16, 7, 9}
{3, 8, 5, 4, 2, 7, 4, 1}
14
Returns: 1
Submissions are judged against all 163 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class GUMIAndSongsDiv2 with a public method int maxSongs(vector<int> duration, vector<int> tone, int T) · 163 test cases · 2 s / 256 MB per case