Logo
(追記) (追記ここまで)

27035번 - Bovine Ballroom Dancing 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 1024 MB109988694.505%

문제

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.

제한

예제 입력 1

4
2
8
5
5
1
4
10
7

예제 출력 1

6

힌트

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.

출처

Olympiad > USA Computing Olympiad > 2003-2004 Season > USACO February 2004 Contest > Blue 2번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /