codeforces-scrape

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

840A.md (1590B)


      1 Source: https://codeforces.com/problemset/problem/840/A
      2 
      3 A. Leha and Function
      4 
      5 time limit per test
      6 
      7 2 seconds
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 Leha like all kinds of strange things. Recently he liked the function *F*(*n*, *k*). Consider all possible *k*-element subsets of the set [1, 2, ..., *n*]. For subset find minimal element in it. *F*(*n*, *k*) — mathematical expectation of the minimal element among all *k*-element subsets.
     22 
     23 But only function does not interest him. He wants to do interesting things with it. Mom brought him two arrays *A* and *B*, each consists of *m* integers. For all *i*, *j* such that 1 ≤ *i*, *j* ≤ *m* the condition *A**i* ≥ *B**j* holds. Help Leha rearrange the numbers in the array *A* so that the sum ![](https://espresso.codeforces.com/680cba4842fc7a381f20e8f82a4b2604531d31a8.png) is maximally possible, where *A*' is already rearranged array.
     24 
     25 Input
     26 
     27 First line of input data contains single integer *m* (1 ≤ *m* ≤ 2·105) — length of arrays *A* and *B*.
     28 
     29 Next line contains *m* integers *a*1, *a*2, ..., *a**m* (1 ≤ *a**i* ≤ 109) — array *A*.
     30 
     31 Next line contains *m* integers *b*1, *b*2, ..., *b**m* (1 ≤ *b**i* ≤ 109) — array *B*.
     32 
     33 Output
     34 
     35 Output *m* integers *a*'1, *a*'2, ..., *a*'*m* — array *A*' which is permutation of the array *A*.
     36 
     37 Examples
     38 
     39 Input
     40 
     41 ```
     42 5  
     43 7 3 5 3 4  
     44 2 1 3 2 3
     45 ```
     46 
     47 Output
     48 
     49 ```
     50 4 7 3 5 3
     51 ```
     52 
     53 Input
     54 
     55 ```
     56 7  
     57 4 6 5 8 8 2 6  
     58 2 1 2 2 1 1 2
     59 ```
     60 
     61 Output
     62 
     63 ```
     64 2 6 4 5 8 8 6
     65 ```