PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#CT0000149. Số còn thiếu thứ k (K-th Missing Number)

Bài tập này chưa được xếp vào lộ trình.

Số còn thiếu thứ k (K-th Missing Number)

K-th Missing Number

Version: Phuoc Hung OJ Extended

Problem Statement

A storage system uses positive integer codes 1,2,3,…1,2,3,\ldots. Exactly nn codes have been assigned, listed as a strictly increasing sequence a1<a2<⋯<ana_1<a_2<\cdots<a_n.

A positive integer not present in this list is a missing number. Listing all missing numbers in increasing order yields an infinite sequence. For example, if the assigned codes are 2,3,72,3,7, the first missing numbers are 1,4,5,6,8,9,…1,4,5,6,8,9,\ldots

There are qq independent queries. Given a positive integer kk in each query, find the kk-th missing number in this increasing sequence.

Input

The first line contains two positive integers nn and qq.

The second line contains exactly nn strictly increasing positive integers a1,a2,…,ana_1,a_2,\ldots,a_n.

Each of the next qq lines contains a positive integer kk, specifying the rank of the missing number to find.

Output

Print exactly qq lines in query order. Each line contains the positive integer that is the kk-th missing number for the corresponding query.

Subtasks

  • Subtask 1 (30 points): 1≤n,q≤301\le n,q\le 30; 1≤a1<a2<⋯<an≤1031\le a_1<a_2<\cdots<a_n\le 10^3; 1≤k≤1031\le k\le 10^3 in each query.
  • Subtask 2 (30 points): 1≤n,q≤20001\le n,q\le 2000; 1≤a1<a2<⋯<an≤1091\le a_1<a_2<\cdots<a_n\le 10^9; 1≤k≤1091\le k\le 10^9 in each query.
  • Subtask 3 (40 points): 1≤n,q≤2⋅1051\le n,q\le 2\cdot 10^5; 1≤a1<a2<⋯<an≤1091\le a_1<a_2<\cdots<a_n\le 10^9; 1≤k≤1091\le k\le 10^9 in each query.

Examples

Example 1

Input

3 5
2 3 7
1
2
3
4
5

Output

1
4
5
6
8

Explanation

Assigned codes are 2,3,72,3,7. Removing them from the positive integers leaves the first five missing values 1,4,5,6,81,4,5,6,8. The queries ask for ranks 1,2,3,4,51,2,3,4,5, so these five values are printed in order.

Example 2

Input

3 3
1 2 3
1
2
10

Output

4
5
13

Explanation

The assigned codes are 1,2,31,2,3, so missing numbers begin 4,5,6,…4,5,6,\ldots. The first is 44, the second is 55, and the tenth is 3+10=133+10=13.

Example 3

Input

4 4
1 3 4 10
1
3
5
8

Output

2
6
8
12

Explanation

Assigned codes are 1,3,4,101,3,4,10. The first missing numbers are 2,5,6,7,8,9,11,122,5,6,7,8,9,11,12. Therefore ranks 1,3,5,81,3,5,8 produce 2,6,8,122,6,8,12.