CF Gym 100960 G. Youngling Tournament set+ tree-like array

Source: Internet
Author: User

G. youngling tournamenttime limit per test2 secondsmemory limit per test256 mebibytesinputStandard InputOutputStandard Output

Yoda, the Grand Master of the Jedi Order, hits on the "idea to" a tournament among younglings. He had not chosen the date yet, but he had already decided on the format of the tournament.

There is N younglings studying in the Jedi Temple. Yoda can feel the force inside younglings, moreover, he can represent the amount of the force inside i-th you Ngling as the number fI.

Therefore, the format of the tournament is the following. At first, Yoda makes the children stand in a row in order of non-increasing  F i . Then, the first youngling in the row competes against all the others with the together. The combat is based in lightsaber battle and is very spectacular. However, Yoda knows, the result doesn ' t depend on anything and the force inside competitors. The youngling wins if he amount of force are not less than the total amount of the force inside all his opponents. In this case, he is considered one of the winners. Otherwise, he loses. Anyway, after that he was removed from the row, and the tournament continues. Again, the strongest (first in the row) Youngling competes against all the others standing in the row in the same format, If he wins, he is also considered one of the winners. After that he was removed and the tournament continues in the same format until there are only one child in the row. He becomes one of the winners automatically and the tournament finishes.

Yoda wants to know the total number of winners. However, as the tournament is postponed again and again, the amount of the force inside the younglings changes from time t o time. Help Yoda to compute the total number of winners after each change.

Input

The first line of input contains a single integer N, the number of younglings in the Jedi Temple (1≤ n ≤100).

The second line contains N integers f1, F2, ..., fn The amount of the force inside the younglings (1≤ fi ≤10).

The third line of the input contains a single integer  M , the number of changes in The force amounts of students (0≤ M ≤50).

The next M lines contain information about the changes. The i-th of these lines describes the i-th change and contains II integers kand F K *, which mean the amount of the force inside the k-th youngling b Ecomes equal to FK * (1≤ kN, 1≤ F k *≤10).

Output

Print M + 1 lines, each of the them containing a single integer.

On the first line, print the number of winners if the tournament is held before all the changes. On line (i + 1) for all I > 0, print the number of winners if the tournament is held after T He first i changes.

Examplesinput
3
2 1 3
3
1 3
2 7
3 5
Output
3
2
3
2
Input
7
2 14 14 15 5 2 5
5
5 2
4 12
5 4
3 10
7 9
Output
4
3
3
3
3
4

Test instructions
Statistics a collection from large to small start delete element, if the value of the current element is greater than the sum of the remaining values, ans++
Exercises
Test instructions is similar to the fib sequence, so there are up to logn answers.
Each time the violence from small to large statistics, find greater than or equal to the current sum value ans++;
As for modifying the direct maintenance of set and statistics and the use of the tree-like array is good

CF Gym 100960 G. Youngling Tournament set+ Tree-like array

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.