atcoder#AGC049F. [AGC049F] Happy Sequence
[AGC049F] Happy Sequence
Score : points
Problem Statement
Integer sequences and , each of length , are given. Snuke is happy if and only if the following condition is met.
- For every integer , $\sum_{1 \leq i \leq N} |A_i-x| \leq \sum_{1 \leq i \leq N} |B_i-x|$ holds.
He decided to change at least elements of to become happy. It costs him to change to . Here, , the value after the change, should be an integer as well.
Find the minimum possible sum of costs in order for Snuke to become happy.
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
3
0 1 4
1 2 3
1 3 2
6
After the following operations, the sum of costs is .
- Change to . This change costs .
- Change to . This change costs .
After the operations, holds, which makes Snuke happy. It is impossible to achieve the goal with sum of costs less than , so the answer is .
20
185 89 216 105 56 383 193 161 75 196 322 180 390 15 206 78 275 338 225 167
161 77 294 117 22 382 218 140 57 231 343 160 397 8 264 68 301 349 295 157
3 1 3 5 2 1 3 4 1 4 2 2 2 2 5 1 1 5 4 3
3758
1
0
0
1
0