#TP0000019. Trang bị áo giáp (Dress’em in Vests!)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Trang bị áo giáp (Dress’em in Vests!)
Dress'em in Vests!
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
The Two-Dimensional Kingdom is preparing its army for a conflict. There are soldiers; soldier requests a bulletproof vest of size . The armoury contains vests; vest has size .
A soldier accepts some variation in size: soldier can wear any vest whose size lies in the inclusive interval , where are nonnegative integers. Each vest can be assigned to at most one soldier, and each soldier receives at most one vest.
Equip the maximum possible number of soldiers and output the assigned soldier–vest pairs. Soldiers and vests are numbered from in input order. Both input size sequences are already sorted in non-decreasing order.
Input
The first line contains integers : the numbers of soldiers and vests, and the two allowed size deviations.
The second line contains integers in non-decreasing order.
The third line contains integers in non-decreasing order.
Output
Print one integer on the first line: the maximum number of equipped soldiers.
Each of the next exactly lines contains two integers , meaning that soldier receives vest . All soldier indices must be distinct, as must all vest indices. Pairs may appear in any order. Any valid maximum matching is accepted.
Subtasks
- Subtask 1 (20 points): ; ; for every element; , .
- Subtask 2 (30 points): ; ; for every element; , .
- Subtask 3 (50 points): ; ; for every element; , .
Examples
Input
5 3 0 0
1 2 3 3 4
1 3 5
Output
2
1 1
3 2
Explanation
Since , a soldier can only wear a vest of exactly the requested size. Vest has size and fits soldier . Vest has size and fits soldier (or ). Vest has size and fits nobody. Therefore at most two pairs can be formed, and the sample prints and .