Loyalty Game
InterviewTime limit2sMemory limit1024 MB
Each type 1 query pours x liters from student i onward, with each student drinking up to their capacity, and type 2 asks a student's total drunk amount.
- Level
Medium5 of 10
- Topics
- Union-find, Simulation, Array
- Solved
- No attempts yet
Problem
Loyalty Game is a game in which students, numbered 1 to , take turns drinking all of liters of liquor in order. Luckily, the students of Hangkong University are very loyal, so each student drinks as much of the liquor passed to them as they can, up to their maximum capacity.
Here, the maximum capacity is the largest amount of liquor a person can drink. When a student drinks up to their maximum capacity, they become drunk, and from then on they forget loyalty and pass the liquor to the next student right away. However, if liquor reaches student and they become drunk while drinking it, or they are already drunk, all the liquor is thrown away.
Two kinds of queries are given in time order. The queries accumulate.
- 1 : Person has liters of liquor, and the game runs from person to person . (; )
- 2 : Print the total amount of liquor student has drunk so far. ()
Input
The first line contains the number of students and the number of queries , separated by a space. ()
The next lines each contain the maximum capacity of student . (; )
From line , the next lines each contain a query in the format described above.
All given numbers are integers.
Output
For each query of type 2, print the answer on its own line, in the order the queries appear.