Healthy Diet
InterviewTime limit2sMemory limit1024 MB
Given m daily bun prices and a shelf life of k days, find the minimum cost of 2 buns per morning and how many buns to buy each day.
- Level
Medium5 of 10
- Topics
- Sliding window, Greedy
- Solved
- No attempts yet
Problem
Volodya is a student, so he needs a healthy diet. For several years, he has eaten two buns and a glass of juice every morning for breakfast.
The buns spoil after days of storage, so every morning he goes to the store and buys fresh buns. The bun prices change every day because of currency fluctuations. Volodya found out the bun prices at the store for the next days. Now he wants to plan his breakfast purchases for these days. Because of the financial crisis and his natural stinginess, Volodya wants to spend as little money on buns as possible. Help him!
Input
The first line contains two integers and : the number of days to plan for and the storage life of the buns (). The second line contains positive integers , the price of a bun on day ().
Output
The first line contains the amount of money that Volodya needs. The second line contains integers , the number of buns Volodya buys on day .