Roller Coaster
InterviewTime limit2sMemory limit1024 MB
Given N groups of sizes a_i and a coaster that holds M people, print the earliest ride index (starting from 0) each group can board, keeping group order.
- Level
Easy3 of 10
- Topics
- Simulation, Greedy
- Solved
- No attempts yet
Problem
In Japan Amusement Group (JAG), members discuss how to make attractions more appealing so that many people come. Lately they have been interested in reducing the stress of waiting in line. A member of JAG found a hypothesis that knowing the waiting time reduces this stress. You will write a program that predicts the waiting time for a roller coaster.
groups stand in line for the roller coaster. The groups are numbered from to , and group has people. People in line ride in ascending order of group number.
The first ride departs at time 0, and a ride departs every minute after that. The roller coaster holds up to people.
All members of a group must ride at the same time. A group does not need the car to be filled to exactly people. Each group wants to ride as early as possible, so a group rides as soon as it can.
Input
The first line contains two integers and , where and . is the number of groups and is the capacity of the roller coaster.
The second line contains integers , where .
Output
Print lines. The -th line contains the time at which group can ride the roller coaster.