#K38262. Shield Activation Maximum Strength
Shield Activation Maximum Strength
Shield Activation Maximum Strength
You are given a series of test cases. Each test case describes a sequence of events occurring on a number of castles that have magic shields. Each castle has a fixed strength value. An event is either an activation or deactivation of a shield at a specified castle.
For each event, when a shield is activated, it is added to the set of active shields; when it is deactivated, it is removed. After processing an event, you should output the maximum strength among all currently active shields. If no shield is active, output 0.
The formula to compute the maximum shield strength can be written as: \( max\_strength = \max \{ s_i \mid i \in A \} \), where \(A\) is the set of indices corresponding to active shields and \(s_i\) is the strength of the shield at castle \(i\).
inputFormat
The first line contains an integer \(t\), the number of test cases. Then, for each test case:
- A line containing an integer \(n\), the number of castles.
- A line containing \(n\) space-separated integers representing the strength values of the shields.
- A line containing an integer \(m\), the number of events.
- \(m\) lines follow, each containing an event in the format "
+ i
" or "- i
", where \(i\) (1-indexed) is the castle number.
outputFormat
For each test case, output a single line with \(m\) space-separated integers. Each integer represents the maximum strength value among all active shields after processing each event. If there is no active shield, output 0 for that event.
## sample1
5
10 20 30 40 50
7
+ 3
+ 1
+ 5
- 3
- 1
+ 2
- 5
30 30 50 50 50 50 20
</p>