#P7628. [COCI 2011/2012 #1] PLES

[COCI 2011/2012 #1] PLES

Description

There are NN boys and NN girls at a dance party, and we know their heights. Each person can dance with at most one partner.

Each boy either wants to dance with a girl taller than him, or with a girl shorter than him. Similarly, each girl either wants to dance with a boy taller than her, or with a boy shorter than her. No boy and girl of the same height want to dance with each other.

If everyone’s wishes are respected, find the maximum number of dancing pairs.

Input Format

The first line contains a positive integer NN.

The next NN lines each contain an integer AiA_i. The absolute value of AiA_i is the height of the ii-th boy. If AiA_i is positive, it means the ii-th boy wants to dance with a girl taller than him; if AiA_i is negative, it means the ii-th boy wants to dance with a girl shorter than him.

The next NN lines each contain an integer BjB_j. The absolute value of BjB_j is the height of the jj-th girl. If BjB_j is positive, it means the jj-th girl wants to dance with a boy taller than her; if BjB_j is negative, it means the jj-th girl wants to dance with a boy shorter than her.

Output Format

Output one line with one integer, the maximum number of dancing pairs.

1
-1800
1800
0
1
1700
-1800
1
2
-1800 -2200
1900 1700
2

Hint

Constraints

For 100%100\% of the testdata, 1N1051 \le N \le 10^5, 1500Ai,Bj25001500 \le |A_i,B_j| \le 2500.

Notes

The score setting of this problem follows the original COCI problem, with a full score of 110110.

Translated from COCI2011-2012 CONTEST #1 T4 PLES.

Translated by ChatGPT 5