포럼
문제 ICPC00326

A. Aquarium Arrangement

설명

You are an employee at the Benelux Aquarium for Piranhas and Catfish. The aquarium is hoping to expand its meagre selection of aquatic life, but lacks the funds to do so. You have been tasked to help promote the aquarium by taking photos of the two exhibits. Taking the first photo went swimmingly, because the catfish were very cooperative. For the piranhas, you have an arrangement of piranhas in mind that will look great on the photo. However, the only way to get the piranhas to move is by recklessly sticking your finger into the water to lure the piranhas. Your goal is to move the piranhas to the desired positions as quickly as possible without losing your finger in the process.

The piranha exhibit can be divided into positions \(1,\ldots,n\) from left to right. The exhibit contains \(k\) piranhas and every position is occupied by at most one piranha. You can stick your finger into any unoccupied position. This will lure the nearest piranha to the left of your finger and the nearest piranha to the right of your finger. These piranhas will swim towards your finger, moving forward one position per second. All other piranhas simply stay in place. A piranha will bite your finger if it reaches the same position, so you must pull your finger away before this happens. Pulling your finger away and sticking it into a different position does not take any time.

For example, suppose there are piranhas at positions \(2\), \(7\) and \(9\). If you stick your finger into the water at position \(4\), the piranhas will be at positions \(3\), \(6\) and \(9\) after one second. You now have to pull your finger away to prevent the piranha at position \(3\) from biting your finger one second later. If you now stick your finger into the water at position \(1\), only the piranha at position \(3\) will move and will end up at position 2 after one second.

제약
입력 형식

The input consists of:
- One line containing two integers \(n\) (\(1\leq n\leq1000\)), the number of positions, and \(k\) (\(1\leq k\leq n\)), the number of piranhas.
- One line containing \(k\) integers \(1\leq p_1<\ldots, the current positions of the piranhas.
- One line containing \(k\) integers \(1\leq d_1<\ldots, the desired positions of the piranhas.

출력 형식

Output the minimum number of seconds needed to get all of the piranhas at the desired positions. If it is impossible to do so, output "impossible".

예제 1
입력
9 3
3 7 9
3 5 9
출력
4
예제 2
입력
8 3
1 5 8
2 4 7
출력
impossible
예제 3
입력
20 6
1 4 7 10 13 20
2 5 8 11 14 17
출력
17
문제 정보

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

출처 ICPC BAPC 2020

평가 및 의견

A. Aquarium Arrangement

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

Log in to rate problems.

개별 의견

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

풀이 제출

A. Aquarium Arrangement

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