Draw Fixing

All submissions for this problem are available.
Siruseri happens to have some of the best chess players in India and one of the most important events in the Siruseri sports calendar is the Annual Chess Challenge where teams from Siruseri and Navalur compete. The event is held alternately at Siruseri and Navalur. This year the tournament is to be held at Sirseri and the Secretary of the Siruseri, who is up for reelection this year, would like to ensure a win for Siruseri. Since starting a war or accusing Navalur of possessing weapons of mass destruction is beyond his scope (and he also has a few more brain cells than the average leader of the free world) he decided to do something clever. Draw Fixing!! To understand what he intended to do, we need to know how the Chess Challege match is organised. Both Siruseri and Navalur are required to send $N$ players. Every player from both teams participates in exactly one game (and so exactly $N$ games are played). The host is expected to draw lots to determine who plays who. Our secretary plans to fix this draw so that the pairings are exactly as he wants them to be. Each chess player has a ELO rating indicating how good he is. The higher the rating the better the player. The secretary knows the rating of each of the players in the Siruseri and Navalur teams and he would like to pair them up so that the number of pairs in which the Siruseri player has a higher ELO rating is maximised. For example, suppose that $N$ is $4$ and the ratings of the players are as below: ![11](https://codechef_shared.s3.amazonaws.com/download/Images/IARCSJUD/DRAWFI... "Figure") Then the secretary can arrange for Siruseri to have the higher rating in $3$ out of $4$ games. He can do this, for example, by pairing them as ($1$, $2$), ($2$, $4$), ($3$, $3$) and ($4$, $1$), where ($i$, $j$) means Player $i$ from Siruseri plays Player $j$ from Navalur. This is the best he can do as no player from Siruseri can beat Player $1$ from Navalur. Your task is help the secretary to find a pairing that maximises the number of pairs with higher rating for Siruseri. ###Input: The first line of the input contains a single integer $N$, denoting the number of players in each team. The next $N$ lines (lines $2$ through $N+1$) list the ratings of the $N$ players in the Siruseri team and the $N$ following lines (lines $N+2$ through $2N+1$) denote the ratings of the players in the Navalur team. ###Output: The first line of the output is an integer $X$ ($0 \leq X \leq N$) representing the number of pairs where the Siruseri player has a higher rating in the optimal pairing. This should be followed by $N$ lines, each containing an integer $n_i$ indicating the player chosen from the Navalur team to play against the $i^{th}$ player from Siruseri. ###Constraints:  $1 \leq N \leq 50000$.  $1 \leq$ all ratings in input $\leq 2000000$  In $50 \%$ of the inputs $1 \leq N \leq 5000$. ###Sample input 4 1873 2134 1900 1600 2450 1860 1700 2120 ###Sample output 3 2 4 3 1Author:  admin2 
Date Added:  17092018 
Time Limit:  2 sec 
Source Limit:  50000 Bytes 
Languages:  C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, rust, SCALA, swift, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, kotlin, PERL6, TEXT, SCM chicken, PYP3, CLOJ, COB, FS 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions