RiseOJ는 solved.ac와 제휴 관계가 없습니다. 티어 아이콘 © solved.ac. solved.ac
포럼
COCI00215

Ograda

Unrated 레이팅 미적용
난이도
1s
시간 제한
32MB
메모리 제한
0
맞았습니다!!
0
제출 수
0.0%
정답률
레이팅

의견: 0

설명

\(4^{th}\) round, February \(18^{th}\), 2012

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 \(10^{9} - 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.

제약

50% of the points for test case will be awarded if niceness is correct, but second line is incorrect or
not outputed at all.

입력 형식

The first line of input contains integer N (\(2 \le N \le 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
출력
7
2 4 1 3
예제 2
입력
10
9 5 1 2 6 7 4 18 20 12
10 40 20 30 50 70 80 100 1000 500
출력
3010
100 80 10 40 50 1000 20 70 500 30

First sample description: Mirko bought boards of heights 1, 2, 3 and 4. Fences similar to Slavko’s
that he can build are:
{1,3,2,4} - niceness 2+1+2=5



{1,4,2,3} - niceness 3+2+1=6



{2,3,1,4} - niceness 1+2+3=6



{2,4,1,3} - niceness 2+3+2=7



{3,4,1,2} - niceness 1+3+1=5
문제 정보

생성자가 기록되지 않았습니다.

출처 COCI 2011/2012 Contest 4

평가 및 의견

Ograda

개요
출제자 난이도 Unrated 레이팅 미적용 의견 0 / 50 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

Ograda

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8