QOJ.ac

QOJ

时间限制: 1 s 内存限制: 1024 MB 总分: 100 可 Hack ✓

#17968. Adding Operations

统计

FuriosaAI develops AI semiconductors for data centers and high-performance edge computing. RNGD is FuriosaAI's second-generation AI accelerator based on a proprietary architecture called TCP(Tensor Contraction Processor), and provides an SDK compatible with major frameworks such as PyTorch.

For RNGD's AI model to carry out an inference task, the model first needs to be compiled into a sequence of RNGD operations. Let's assume the following situation, which is a simplification of the actual compilation process.

The basic unit of time for an RNGD operation is a cycle, and the model's execution needs to be completed within $H$ cycles. Let the $H$ cycles be labeled cycle $1$, cycle $2$, $\cdots$, cycle $H$ sequentially.

There are $N$ operations in the compiled AI model. The execution of the $i$-th operation starts at cycle $A_i$ and ends at cycle $B_i$. Note that there may be operations whose cycles overlap.

While executing the compiled model, RNGD has been requested to execute one additional operation. The additional operation must not have overlapping cycles with any of the $N$ other operations and must be executed within the $H$ cycles. Specifically,

  • Let $T$ be the number of cycles the additional operation takes to complete. In other words, if the additional operation begins executing at cycle $S$, it terminates at cycle $S+T-1$.
  • While the additional operation is being executed, no other operations should be executed.
  • $1\leq S\leq S+T-1 \leq H$ should hold.

The value of $T$ may differ based on the type of operation to be added. To test various cases, we will consider $Q$ different values of $T$. Given $T_i$, denoting the number of cycles required for the additional operation at the $i$-th case, write a program that calculates the number of possible starting cycles $S$ quickly.

Note that each case is handled independently. In other words, each of the additional operations is only effective for its corresponding case.

Input

The first line of input contains two space-separated integers $N$, denoting the number of operations of the AI model, and $H$, denoting the total number of cycles. ($0 \leq N \leq 200000$; $1 \leq H \leq 10^9$)

The $i$-th of the following $N$ lines contains two space-separated integers $A_i$ and $B_i$, denoting the beginning and ending cycles of the $i$-th operation. ($1 \leq A_i \leq B_i \leq H$)

The next line contains $Q$, denoting the number of cases to be tested. ($1 \leq Q \leq 200000$)

Each of the following $Q$ lines contains $T_i$, denoting the number of cycles required for the additional operation. ($1 \leq T_i \leq H$)

Output

Print $Q$ lines in total; the answer for each case in a single line.

Examples

Input 1

3 30
5 8
12 19
14 23
3
2
4
6

Output 1

11
5
2

Input 2

0 4
2
1
2

Output 2

4
3

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.