Колеги, зада4ата е от C#, аз я мъ4а на Java. От Stacks and Queues.

Не мога да измисля как след като дневните калории станат отрицателни, отрицателната 4аст да се прехвърли към следващия ден. (с положит. стойност)

C# Advanced Retake Exam - 13 April 2022 - SoftUni Judge   link Junge

Pastebin: Meals -

И принтът не е наред съответно.

Ще се радвам и на изцяло ново реш. - явно не съм тръгнал по оптимален на4ин.



You will be given two lines of input. The first line will be an array of strings, separated by a single space, representing meals that John can eat. The second line will be an array of integers, separated by a single space, representing the maximum calories intake per day.

Here is a table with the exact meals and their calories:











Start calculating calories as follows: take the first meal’s calories and the last element in the sequence of calorie intake for a day. Each time John eats a meal, the calories intake for the current day should be decreased by the calories of the given meal, and the current meal should be removed from the collection. When the calories intake for the given day goes to zeroremove them from the collection, and continue to the next day. If the calories for the given day go below zero, take as many calories as possible from the meal, so the current daily calories intake reaches zero. The rest of the meal’s calories should be subtracted from the next day in the calorie intake sequence.

For more clarification, check the provided examples.

The program stops when there are no more meals to be eaten, or there are no more daily calories to be calculated.


  • On the first line, a sequence of strings will be given representing mealsseparated by a single space (" ").
  • On the second line, a sequence of integers will be given, representing the daily calories intakeseparated by a single space (" ").


  • As a result, you should print two lines for output:
    • If John menage to eat all the given meals print:

"John had {number of meals} meals."

"For the next few days, he can eat {dailyCalories1, dailyCalories2, etc.} calories."

Separate the daily calories intake by comma and space (", ").

  • If John could not eat every meal:

"John ate enough, he had {number of meals} meals."

"Meals left: {meal1, meal2, etc.}."

Separate the meals by comma and space (", ").


  • The daily calories will be in the range [1200…4000].
  • No recursion is needed for solving this problem.
  • The input will be always valid.
  • There will be no case where daily calories and meals go to zero simultaneously.




salad soup salad steak

2500 1800 1500

John had 4 meals.

For the next few days, he can eat 1320, 2500 calories.