#C2216. Secret Bunker Security System
Secret Bunker Security System
Secret Bunker Security System
You are in charge of a secret bunker security system. The system maintains an array of integers that is modified through a series of queries. There are three types of queries:
- Update query:
1 x1 x2 ... xk
replaces the current sequence with the list of integers provided. - Sum query:
2 K
asks to compute the sum of the smallest \(K\) elements in the current sequence. Formally, if the current sequence is \(A\) then sort it to obtain \(A'\) and output \(\sum_{i=1}^{K} A'_i\). - Append query:
3 x
appends the integer \(x\) to the current sequence.
The queries are processed in order. For each sum query (type 2), your program must print the result to standard output.
inputFormat
The first line contains an integer \(Q\) representing the number of queries. Each of the following \(Q\) lines contains a query in one of the following formats:
1 x1 x2 ... xk
— Update the current sequence with the given integers.2 K
— Output the sum of the smallest \(K\) elements in the current sequence.3 x
— Append the integer \(x\) to the current sequence.
All input is provided through standard input (stdin).
outputFormat
For every sum query (query type 2), output the computed sum on a new line using standard output (stdout).
## sample7
1 5 2 9 1
2 3
3 4
2 3
1 8 7 5
2 2
3 1
8
7
12
</p>