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

20329번 - Aquarium 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 512 MB64231944.186%

문제

The aquarium at which you work 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.

입력

  • 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<p_k\leq n,ドル the current positions of the piranhas.
  • One line containing $k$ integers 1ドル\leq d_1<\ldots<d_k\leq n,ドル 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

예제 출력 1

4

예제 입력 2

8 3
1 5 8
2 4 7

예제 출력 2

impossible

예제 입력 3

20 6
1 4 7 10 13 20
2 5 8 11 14 17

예제 출력 3

17

힌트

출처

ICPC > Regionals > Europe > Northwestern European Regional Contest > The UK & Ireland Programming Contest > UKIEPC 2020 A번

ICPC > Regionals > Europe > Northwestern European Regional Contest > Benelux Algorithm Programming Contest > BAPC 2020 A번

Camp > Petrozavodsk Programming Camp > Winter 2021 > Day 3: Nordic+ Contest 2020 A번

  • 문제를 만든 사람: Freek Henstra
(追記) (追記ここまで)

출처

대학교 대회

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

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