#FT0000030. Đa tập – Chèn và xóa theo thứ hạng (Multiset)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Đa tập – Chèn và xóa theo thứ hạng (Multiset)
Multiset
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
You are given a multiset of integers. Unlike a set, duplicate values are allowed and each occurrence has its own position in sorted order. Initially, contains positive integers provided in nondecreasing order.
Process operations, represented by integers :
- If , insert one occurrence of value .
- If , sort the current multiset in nondecreasing order and remove one occurrence of the element at rank , starting from rank . Every removal is guaranteed to be valid.
After all operations, print 0 if the multiset is empty. Otherwise, print any value still contained in the multiset; the minimum or maximum is not required. A value no longer present is invalid.
Input
- Line 1: integers , initial multiset size and operation count.
- Line 2: exactly integers in nondecreasing order.
- Line 3: exactly nonzero integers , representing the operations in order. These are operations on the same multiset, not separate test cases.
Output
Print exactly one integer: 0 if the final multiset is empty, or any value that occurs in the final multiset otherwise. Multiple different outputs may be accepted.
Subtasks
Subtask 1 (20 points):
- .
- .
- .
- For each : .
- For each : at the time of removal.
- Every is nonzero; duplicate values retain their multiplicities.
Subtask 2 (30 points):
- .
- .
- .
- For each : .
- For each : at the time of removal.
- Every is nonzero; duplicate values retain their multiplicities.
Subtask 3 (50 points):
- .
- .
- .
- For each : .
- For each : at the time of removal.
- Every is nonzero; duplicate values retain their multiplicities.
Examples
Input
5 4
1 2 3 4 5
-5 -1 -3 -1
Output
3
Explanation
The initial sorted multiset is .
-5removes the fifth element, , leaving .-1removes the first element, , leaving .-3removes the third element, , leaving .-1removes the first element, , leaving .
Only remains, so this sample's output is 3. In other cases with several remaining values, any of them would be accepted.