#1060
Unrated
OGRADA
스페셜 저지채점 준비중
시간 제한
1s
메모리 제한
32MB
제출
0
정답
0
맞힌 사람
0
정답 비율
0.0%

문제

Author: Ivan Katanić

In Mirko’s village all fences are made of exactly N boards with different heights. Mirko doesn’t have his own fence yet, so he decided to build one. Each board is represented by a positive integer less than 109 - it’s height. We define the niceness of the fence as a sum of height differences between adjacent boards. Mirko already bought the boards, but he doesn’t know how to order them into a fence. He would like his fence to be similar to Slavko’s fence, but also to be as nice as possible. We say that two fences are similar if ordering of adjacent boards is the same in both fences, i.e. if i-th board of one fence is smaller (or larger) than (i+1)-st, than the same must hold for that boards of the other fence. Given Slavko’s fence configuration, and heights of boards that Mirko bought, put Mirko’s fence together so that it is similar to Slavko’s but also as nice as possible. If there is more than one solution, output any of them.

입력

The first line of input contains integer N (2 ≤ N ≤ 300 000), number of boards in each fence. The following line conatins N different positive integers representing Slavko’s fence. The following line contains N different positive integers representing heights of boards Mirko bought for his fence.

출력

The first line of output should contain the maximum possible niceness of Mirko’s fence. The following line should contain N integers, Mirko’s boards in optimal order as described.

예제 입력 1

4
5 7 4 9
1 2 3 4

예제 출력 1

7
2 4 1 3

예제 입력 2

10
9 4 1 2 6 7 4 18 20 12
10 40 20 30 50 70 80 100 1000 500

예제 출력 2

3010
100 80 10 40 50 1000 20 70 500 30
코드 제출

이 문제는 현재 제출할 수 없습니다.

이 현상이 잘못되었다고 생각될 경우 관리자한테 문의주세요.

내 제출
제출 내역이 없습니다.
맞은 사람
아직 맞은 사람이 없습니다.
난이도 투표
Unrated0명 투표
로그인 후 AC 받으면 투표할 수 있습니다.
전체 제출
제출 내역이 없습니다.