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

#BS0000129. Món hàng đẹp nhất theo ngân sách (Most Beautiful Item for Each Query)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Món hàng đẹp nhất theo ngân sách (Most Beautiful Item for Each Query)

Most Beautiful Item for Each Query

Source: LeetCode

Version: Phuoc Hung OJ Extended

Problem Statement

There are nn items. Item ii has price pip_i and beauty bib_i. For each of the qq independent budgets XjX_j, choose at most one item whose price does not exceed XjX_j, maximizing its beauty. If no item is affordable, answer 00.

Input

The first line contains n,qn,q. Each of the next nn lines contains pi,bip_i,b_i. The final line contains qq budgets X1,…,XqX_1,\ldots,X_q.

Output

Print qq integers in query order, separated by spaces.

Subtasks

  • Subtask 1 (20 points): 1≤n≤201\le n\le 20; 1≤q≤201\le q\le 20; 1≤pi,bi,Xj≤1091\le p_i,b_i,X_j\le10^9, 1≤i≤n1\le i\le n, 1≤j≤q1\le j\le q.
  • Subtask 2 (30 points): 1≤n≤20001\le n\le 2000; 1≤q≤20001\le q\le 2000; 1≤pi,bi,Xj≤1091\le p_i,b_i,X_j\le10^9, 1≤i≤n1\le i\le n, 1≤j≤q1\le j\le q.
  • Subtask 3 (50 points): 1≤n≤1000001\le n\le 100000; 1≤q≤1000001\le q\le 100000; 1≤pi,bi,Xj≤1091\le p_i,b_i,X_j\le10^9, 1≤i≤n1\le i\le n, 1≤j≤q1\le j\le q.

Examples

Input

5 6
1 2
3 2
2 4
5 6
3 5
1 2 3 4 5 6

Output

2 4 5 5 6 6

Explanation

Budget 11 allows only beauty 22. Budget 22 adds the item of beauty 44. Budget 33 allows four items and the best beauty is 55; budget 44 adds none. Budgets 55 and 66 can afford beauty 66. Therefore print 2 4 5 5 6 6.