задача Winecraft от Lists - More Exercises; Prog Fund Extended
Здравейте. Имам голям проблем с тази задача. Няколко дни се опитвам да я реша.
Условието:
You will be given a sequence of integers, which will represent grapes. On the next line you will be given N - an integer, indicating the growth days. You must increment every integer in the list by 1 N times. However, if one of the grapes’ value is greater than the grape to its left and is also greater than the one to his right, it should steal the values, which would have been incremented to its neighbors, and add them to itself, instead of being incremented by 1 like normal (note: if any of the greater grapes’ neighboring grapes have a value of 0, DON’T decrement it and DON’T add its value to the greater grape).
Lesser grapes don’t get incremented, but instead they have their values decremented by 1 by their neighboring greater grapes, therefore their values get added to the greater grapes.
After you're done with the growing (processed the grapes N times), every grape which has a value, lower than N should be removed.
The process should then repeat, again incrementing everything N times, where the greater grapes steal from the lesser grapes, until your list contains less than N grapes.
Решението:https://pastebin.com/TUEMa1VG. Разгледах много внимателно видеото. Следвах всяка инструкция стъпка по стъпка и разбрах, че всеки метод поотделно работи правилно. Още във Visual Studio не мога да въвеждам данни в конзолата. В Judge излезе, че няма достатъчно памет, после че няма достатъчно време. Моля някой да ми даде съвет какво да направя. Благодаря предварително.
Благодаря много за добрите обяснения.