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

20036번 - Ball Alignment 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 512 MB4701058427.010%

문제

Balls are placed on a curved structure as shown in Figure A.1, and each ball has a number written on it. Due to the law of gravity, all balls naturally gather near the lowest spot of the structure. The permitted action to change the position of the balls is to “pick a ball, lift it up, and place it on the far left or on the far right”. This action will naturally change the location of some balls due to the law of gravity.

Figure A.1

Figure A.2 shows how the locations of the balls change when the marked ball 5 was picked up in Figure A.1 and placed on the far right.

Figure A.2

When n balls are arranged on a curved structure we want to sort the numbers written on the balls in non- decreasing order by repeating the permitted actions. In Figure A.2, if ball 7 is picked up and placed on the far right and ball 2 far left, all the numbers on balls are sorted in non-decreasing order.

Given an arrangement of n balls, write a program which helps to rearrange all the numbers written on the balls in non-decreasing order by selecting minimum number of balls and relocating them through the permitted actions.

입력

Your program is to read from standard input. The input starts with a line containing an integer n (1 ≤ n ≤ 105), which denotes the number of balls. Each of the following n lines contains an integer v (1 ≤ v ≤ 109), which is the number written on a ball. Notice that some balls may have the same number written on them.

출력

Your program is to write to standard output. Print exactly one line. The line should contain the minimum number of balls picked up and relocated to align all the numbers written on the n balls in non-decreasing order.

제한

예제 입력 1

4
21
44
39
41

예제 출력 1

1

예제 입력 2

7
11
12
25
16
11
18
25

예제 출력 2

2

힌트

출처

ICPC > Regionals > Asia Pacific > Korea > Nationwide Internet Competition > Seoul Nationalwide Internet Competition 2020 A번

  • 데이터를 추가한 사람: kyo20111
(追記) (追記ここまで)

출처

대학교 대회

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

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