TAP2013G - War

War, an event worthy only of appearance in literature, movies or perhaps programming contests, has reached the Nlogonian empire, which is facing the neighboring empire of Quadradonia.

War protocols agreed upon by both parties indicate that the war will be waged in successive battles, in each of which a different soldier from each empire will face one another, so that each soldier will take part in exactly one battle. The empire that wins more battles will then win the war.

Each empire has an army formed by S soldiers, and each soldier has a certain combat skill. In each battle between two soldiers, the one with greatest combat skill wins the battle. If both soldiers have the same combat skills, the battle is declared a draw and technically no side claims victory. The spies of Nlogonia have intercepted secret information concerning the combat skill of each soldier of Quadradonia's army, so Nlogonia's queen requires your assistance in order to calculate the maximum number of battles that can be won during the war if her soldiers are sent in the appropriate order.

Input

The first line contains an integer number S representing the number of soldiers in each army (1 ≤ S  105). The second line contains S integer numbers Qi representing the combat skills of the different soldiers of Quadradonia's army, in the order in which the battles shall take place ( Qi  109 for i = 1, ..., S). The third line contains S integer numbers Ni representing the combat skills of the different soldiers in Nlogonia's army, in an arbitrary order ( Ni  109 for i = 1, ..., S).

Output

Print a line containing a single integer number representing the maximum number of battles that Nlogonia can win during the war.

Example 1

Input:
3
2 1 1000000000
1 1 2

Output:
1

Example 2

Input:
4
6 3 1 4
2 7 4 3

Output:
3

Added by:Fidel Schaposnik
Date:2013-10-07
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64
Resource:Argentinian Programming Tournament 2013

hide comments
2015-01-02 06:51:38 Sayak Haldar
I got ac with O(nlogn)+O(n) approach,but when is comes to O(nlogn)+O(logn) approach it is giving so much wa..:/


Last edit: 2015-01-02 07:01:20
2014-09-29 17:03:31 Prajval Prabhakar
ac in first go :)
2014-09-29 17:03:31 nikhil_nihal
getting WA in 35th running..
any help pls..
2014-09-29 17:03:31 [Lakshman]
@Sahil Dua Yes there is much faster way to do this instead of linear comparison (which is O(n)) you can use Binary search which is O(log n) .
2014-09-29 17:03:31 Sahil Dua
I am getting TLE at one of the last test cases. I am just sorting two arrays and comparing their elements with a logic. Seems to be a O(nlogn) solution. Better approach?

EDIT: Ok, finally got AC but in 0.39s. How to improve timing?

Last edit: 2014-07-14 08:19:07
2014-09-29 17:03:31 pvkcse
same logic in c# got AC but in python it is WA...!!!
2014-09-29 17:03:31 ivar.raknahs
think mathematically:)
AC in first attempt.
2014-09-29 17:03:31 innovolt
easy
2014-09-29 17:03:31 californiagurl
my code takes .4 sec. how can i speed up?
is there a way without sorting?
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.