아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Bovine Ballroom Dancing

면접 대비

시간 제한1초메모리 제한1024 MB

요약
모든 수소와 암소를 짝지어 높이 차의 합이 최소가 되는 짝을 구한다.
난이도

보통10점 중 4점

유형
그리디, 정렬, 배열, 수학
정답자
아직 제출이 없습니다

문제

Cows are remarkably bad dancers. Nonetheless, Farmer John has discovered that graceful cows tend to produce more milk and therefore has enrolled his entire herd cows in a ballroom dance class. In the first class meeting, the N (1 ≤ N ≤ 1,000) boy cows (a.k.a. bulls) and N girl cows in the herd must first be paired up into couples. Two cows make a good couple if they have relatively similar heights (i.e., the difference of their heights is small). Given the heights of all the cows, your task is to find a pairing-up of the cows that minimizes the total sum of all height differences over all couples.

입력

  • Line 1: The single integer N.
  • Lines 2..N+1: Each line contains an integer giving the height of a boy cow.
  • Lines N+2..2N+1: Each line contains an integer giving the height of a girl cow.

출력

  • Line 1: A single integer giving the sum of height differences in an "optimal" pairing up of the cows.

힌트

There are 4 boy cows of heights 2, 8, 5, and 5, and there are 4 girl cows of heights 1, 4, 10, and 7.

The best pairing is as follows (in terms of heights): 2-1 8-10 5-4 5-7. The total sum of height difference for this pairing is 6.

예제1

  1. 예제 1

    입력
    4
    2
    8
    5
    5
    1
    4
    10
    7
    
    예상 출력
    6