National Informatics OlympiadNational RoundRazgrad, 26 to 28 April, 2013Group D, 6th gradeTask D3. RABBITSIn a living laboratory N rabbits that are numbered from 1 to N.In the laboratory, there is a row of N cells, arranged in a row and numbered from1 to N. For an array of cells has a number of feeders, which are alsonumbered from 1 to N, but disordered, ie in some order h1, h2, ... ..hN.Rabbits are located in cells disordered, as in Box 1 is rabbit m1, inBox 2 - rabbit m2, etc. and eat according to the principle "rabbit with number k eatFeed number k ", by simply moving it. If the rabbit number k isin cell number p, and the link with the number k is against cell number q, it rabbit with number kmust travel a distance | pq | to the feeder in order to eat there bycarrot.rabbitsfeedersWith such an arrangement of racks rabbit number 1 will travels3 distance before eating rabbit 2 - a distance of 2, 3 rabbit - a distance of 4, rabbit 4It will not move, and rabbit 5 will have to walk a distance of 1.Write a program rabbits, which receives the location of rabbits andfeeders and determines the longest distance that a rabbit will needto travel to reach your carrot.InputThe first line of standard input, one integerN- including number of rabbits.From the second line introduces the numbers from 1 to N, mixed in some way -numbers of rabbits living in the first, second, etc. cells.Third row introducing numbers from 1 to N, mixed in some way -numbers of racks located on the first, second, etc. cells.ExitThe standard output should put an integer -the maximum distance you have to go rabbit cage to the feederin order to feed.Limitations2 ≤ N ≤ 100 000, in 50% of tests 2 ≤ N ≤ 1000Example (refer to the figure above)Input Output52 1 5 4 33 5 2 4 142 1 5 4 33 5 2 4 1
đang được dịch, vui lòng đợi..