Dining Hall Support Dispatch
Time limit1sMemory limit1024 MB
Given a day d and a soldier number x, find how many times the dispatch program picks soldier x through day d.
- Level
Medium7 of 10
- Topics
- Simulation, Greedy, Math
- Solved
- No attempts yet
Problem
Soldiers from units near the military dining hall go to the hall to help with its work. This duty is called dining support. The dining support officer decides who goes on dining support and when.
At first, the officer sent three soldiers chosen at random to the hall each day. Tired of picking them by hand every day, the officer built a dispatch program to make the selection simpler and more systematic.
The dispatch program runs every morning and picks soldiers in order of how few dining support duties they have had on that day. Specifically, it selects the three soldiers with the smallest sum of two counts: the number of times they were picked at random before the program started, and the number of times the program picked them from its first day up to the day before the current dispatch. If two soldiers have the same count, the one with the smaller service number is picked first.
Now the soldiers know the dispatch is not random, and they want to know the results in advance. They have started calling the officer to ask how many times the program will pick them through day of operation. Given the number of days and a soldier's service number, find how many times the program picks that soldier.
Input
The first line contains the number of soldiers .
The second line contains , the number of times each soldier from service number to was picked at random before the program started, separated by spaces.
The third line contains the number of calls .
The next lines each contain a day and a service number , separated by a space.
Output
For each call, in the order the calls were received, print one integer on its own line: the number of times the program picks that soldier through day .