cswork / OAOpen practice workspace

Capital OneOA #8

File Transfer Segments — Count Unique After Each Byte

Estimated MediumJudge-ready

Topics (AI-labelled)HashingPrefix & Ranges

Bytes arrive one at a time; after each arrival, count the file segments that have been completely received. A segment covers the half-open interval [start,start+length).

Input

n m; then n lines start length; the last line contains m non-negative byte offsets. Site supplement: n,m≤1000, total interval length ≤20000, offsets ≤200000.

Output

Output m integers separated by spaces; the i-th number is the number of completed segments after the first i bytes have arrived.

Example 1

Input:

3 7
0 3
2 3
8 1
2 0 1 3 2 8 8

Output:

0 0 1 1 1 2 2

Example 2

Input:

2 4
5 1
0 2
0 1 0 5

Output:

0 1 1 2

Example 3

Input:

1 3
0 1
2 2 2

Output:

0 0 0

Editorial

Loading solution…