Problem Preparation
InterviewTime limit2sMemory limit256 MB
Maintain an array under point increments and decrements, and after each update answer the sum of ceil(t_i / k) for a given k.
- Level
Medium7 of 10
- Topics
- Math, Prefix sum, Array, Implementation
- Solved
- No attempts yet
Problem
Andrew has written programming problems for a contest and now he plans to prepare them. He estimates that preparing problem takes minutes in total. Andrew wants to invite his friends to share the work.
He does not know how many friends will agree to help, but he wants to split the work fairly. So for problem he picks an integer , and every friend who helps spends minutes on that problem. Problem is completely prepared once the total time his friends spend on it is at least minutes. With friends helping, is the smallest integer that satisfies .
Whenever Andrew realizes that he misjudged the difficulty of a problem, he increases or decreases by 1.
You are given the initial estimates . Process queries in the given order. Each query is one of the following.
1 i: Andrew increases by 1.2 i: Andrew decreases by 1.3 k: Andrew wants to know how many minutes one friend spends preparing all problems when friends help.
Input
The first line contains two integers and , the number of problems and the number of queries. ()
The second line contains integers , where is Andrew's initial estimate for problem . ()
Each of the next lines contains one query as two integers and . If is 1, then increases by 1. If is 2, then decreases by 1. In both cases . If is 3, then you must report the time one friend spends when friends help. In this case .
After every query all values of stay between 1 and .
Output
For every query with equal to 3, print on its own line the total time one friend spends preparing all problems, that is .