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

#GD0000167. Khôi phục thời tiết (Restore the Weather)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Khôi phục thời tiết (Restore the Weather)

Restore the Weather

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

You are given forecast temperatures a1,…,ana_1,\ldots,a_n and the same days' actual temperatures in shuffled order b1,…,bnb_1,\ldots,b_n. Reorder the multiset bb into cc so that ∣ai−ci∣≤k|a_i-c_i|\le k for all ii. A valid rearrangement is guaranteed.

Input

The first line contains n,kn,k. The second contains nn forecast values aia_i; the third contains nn actual values bib_i.

Output

Print nn values cic_i in day order, using exactly the input multiset bb and satisfying ∣ai−ci∣≤k|a_i-c_i|\le k.

Subtasks

  • Subtask 1 (20 points): 1≤n≤81\le n\le 8; 0≤k≤1090\le k\le 10^9; −109≤ai,bi≤109-10^9\le a_i,b_i\le 10^9; bảo đảm tồn tại đáp án.
  • Subtask 2 (30 points): 1≤n≤30001\le n\le 3000; 0≤k≤1090\le k\le 10^9; −109≤ai,bi≤109-10^9\le a_i,b_i\le 10^9; bảo đảm tồn tại đáp án.
  • Subtask 3 (50 points): 1≤n≤1051\le n\le 10^5; 0≤k≤1090\le k\le 10^9; −109≤ai,bi≤109-10^9\le a_i,b_i\le 10^9; bảo đảm tồn tại đáp án.

Examples

Input

5 2
1 3 5 3 9
2 5 11 2 4

Output

2 2 5 4 11

Explanation

Sort the forecast positions and the actual values, pair corresponding ranks, and restore original day indices. The resulting c=[2,2,5,4,11]c=[2,2,5,4,11] has absolute deviations 1,1,0,1,21,1,0,1,2, all at most 22, and retains the exact original multiset of actual temperatures.