Triangle Collection

아직 제출이 없습니다시간 제한4초메모리 제한1024 MB

문제

Alice has a collection of sticks. Initially, she has c_c\_{\ell} sticks of length \ell for each =1,,N\ell = 1, \ldots, N.

Alice would like to use her sticks to make some isosceles triangles. An isosceles triangle is made of two sticks of the same length, say \ell, and a third stick with a length between 11 and 212\ell - 1 inclusive. Note that the triangles must strictly obey the triangle inequality, and equilateral triangles are okay. Each stick may be used in at most one triangle. Alice would like to know the maximum number of isosceles triangles she can make with her sticks.

There are QQ events that change the collection of sticks she has. The ii-th event consists of two integers _i\ell\_{i} and d_id\_i, representing that the number of sticks of length _i\ell\_{i} changes by d_id\_{i}. Note that d_id\_i may be positive, negative, or even 00, but Alice will never have a negative number or more than 10910^9 sticks of each length.

Your task is to determine the maximum number of isosceles triangles Alice can make after each event if she uses her sticks optimally.

입력

The first line of input contains two space-separated integers NN and QQ.

The second line of input contains NN space-separated integers c_1,c_2,,c_Nc\_1, c\_2,\ldots, c\_N (0c_i109)(0 \le c\_i \le 10^9), representing Alice's initial collection.

The next QQ lines of input each contain two space-separated integers _i\ell\_i and d_id\_i (1_iN,109d_i109)(1 \le \ell\_i \le N, -10^9 \le d\_i \le 10^9), representing an event.

Initially and after each event, the number of sticks of length \ell is between 00 and 10910^9 for all =1,,N\ell = 1,\ldots, N.

출력

Output QQ lines each containing a single integer, the answer after each event.

제한

  • 1N,Q200,0001 \le N,Q \le 200\\,000