codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

161A.md (3038B)


      1 Source: https://codeforces.com/contest/161/problem/A
      2 
      3 A. Dress'em in Vests!
      4 
      5 time limit per test
      6 
      7 3 seconds
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 stdin
     16 
     17 output
     18 
     19 stdout
     20 
     21 The Two-dimensional kingdom is going through hard times... This morning the Three-Dimensional kingdom declared war on the Two-dimensional one. This (possibly armed) conflict will determine the ultimate owner of the straight line.
     22 
     23 The Two-dimensional kingdom has a regular army of *n* people. Each soldier registered himself and indicated the desired size of the bulletproof vest: the *i*-th soldier indicated size *a**i*. The soldiers are known to be unpretentious, so the command staff assumes that the soldiers are comfortable in any vests with sizes from *a**i* - *x* to *a**i* + *y*, inclusive (numbers *x*, *y* ≥ 0 are specified).
     24 
     25 The Two-dimensional kingdom has *m* vests at its disposal, the *j*-th vest's size equals *b**j*. Help mobilize the Two-dimensional kingdom's army: equip with vests as many soldiers as possible. Each vest can be used only once. The *i*-th soldier can put on the *j*-th vest, if *a**i* - *x* ≤ *b**j* ≤ *a**i* + *y*.
     26 
     27 Input
     28 
     29 The first input line contains four integers *n*, *m*, *x* and *y* (1 ≤ *n*, *m* ≤ 105, 0 ≤ *x*, *y* ≤ 109) — the number of soldiers, the number of vests and two numbers that specify the soldiers' unpretentiousness, correspondingly.
     30 
     31 The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1 ≤ *a**i* ≤ 109) in non-decreasing order, separated by single spaces — the desired sizes of vests.
     32 
     33 The third line contains *m* integers *b*1, *b*2, ..., *b**m* (1 ≤ *b**j* ≤ 109) in non-decreasing order, separated by single spaces — the sizes of the available vests.
     34 
     35 Output
     36 
     37 In the first line print a single integer *k* — the maximum number of soldiers equipped with bulletproof vests.
     38 
     39 In the next *k* lines print *k* pairs, one pair per line, as "*u**i* *v**i*" (without the quotes). Pair (*u**i*, *v**i*) means that soldier number *u**i* must wear vest number *v**i*. Soldiers and vests are numbered starting from one in the order in which they are specified in the input. All numbers of soldiers in the pairs should be pairwise different, all numbers of vests in the pairs also should be pairwise different. You can print the pairs in any order.
     40 
     41 If there are multiple optimal answers, you are allowed to print any of them.
     42 
     43 Examples
     44 
     45 Input
     46 
     47 ```
     48 5 3 0 0  
     49 1 2 3 3 4  
     50 1 3 5
     51 ```
     52 
     53 Output
     54 
     55 ```
     56 2  
     57 1 1  
     58 3 2
     59 ```
     60 
     61 Input
     62 
     63 ```
     64 3 3 2 2  
     65 1 5 9  
     66 3 5 7
     67 ```
     68 
     69 Output
     70 
     71 ```
     72 3  
     73 1 1  
     74 2 2  
     75 3 3
     76 ```
     77 
     78 Note
     79 
     80 In the first sample you need the vests' sizes to match perfectly: the first soldier gets the first vest (size 1), the third soldier gets the second vest (size 3). This sample allows another answer, which gives the second vest to the fourth soldier instead of the third one.
     81 
     82 In the second sample the vest size can differ from the desired size by at most 2 sizes, so all soldiers can be equipped.