Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class Guitar
- {
- static void Main()
- {
- string volumeChangesInput = Console.ReadLine();
- int initialVolB = int.Parse(Console.ReadLine()),
- maxVolM = int.Parse(Console.ReadLine());
- string[] delimiters = { ", " };
- string [] volumeChanges = volumeChangesInput.Split(delimiters, StringSplitOptions.RemoveEmptyEntries);
- int[,] results = new int[volumeChanges.Length + 1, maxVolM+1];
- //Fill in the first row the initial volume level
- results[0, initialVolB] = 1;
- //Fill the table with the possible changes
- for (int row = 1; row < results.GetLength(0); row++)
- {
- for (int col = 0; col < results.GetLength(1); col++)
- {
- if (results[row-1,col] == 1)
- {
- int tempUp = col+ int.Parse(volumeChanges[row-1]);
- int tempDown = col - int.Parse(volumeChanges[row-1]);
- if (tempUp >= 0 && tempUp <= maxVolM)//possible volume
- {
- results[row, tempUp] = 1;
- }
- if (tempDown >= 0 && tempDown <= maxVolM)
- {
- results[row, tempDown] = 1;
- }
- }
- }
- }
- //Find the result and print it
- int maxVol = -1;
- for (int i = results.GetLength(1)-1; i >= 0; i--)
- {
- if (results[volumeChanges.Length, i] == 1)
- {
- maxVol = i;
- break;
- }
- }
- Console.WriteLine(maxVol);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement