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

35078번 - Group Photo 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
4 초 2048 MB84375.000%

문제

The members of the No-Weather-too-Extreme Recreational Climbing society completed their 200ドル$th successful summit today! To commemorate the occasion, you will take a picture of all the members standing together in one row.

After the photo for the 100ドル$th summit eight years ago turned into a moderate fiasco, you are determined to get things right this time and make sure that people are arranged in an aesthetically pleasing way before taking the photo.

As this group is all about climbing mountains, you want the heights of the climbers in the photo to make the shape of a mountain. More precisely, the climbers should be arranged such that their heights are first increasing and then decreasing (the increasing or decreasing part is allowed to be empty). The heights of all climbers are pairwise distinct, so for simplicity we will say that the shortest climber has height 1ドル,ドル the second-shortest climber has height 2ドル,ドル and so on.

The climbers have already positioned themselves in a row in some arbitrary way that is not necessarily visually pleasing. You will select a subset of the climbers and rearrange their positions among themselves, with all other climbers staying exactly where they are. To keep chaos to a minimum, you want the number of moving climbers to be as small as possible.

What is the size of the smallest subset of climbers such that it is possible to reorder them so that the sequence of heights becomes first increasing and then decreasing?

입력

The input consists of:

  • One line with an integer $n$ (1ドル\leq n\leq 5 \cdot 10^5$), the number of climbers.
  • One line with $n$ distinct integers $a_1, \ldots, a_n$ (1ドル \leq a_i \leq n$ for each $i$), where $a_i$ is the height of the $i$th climber in the current arrangement.

출력

Output the minimum number of climbers who need to move.

제한

예제 입력 1

6
1 6 4 3 2 5

예제 출력 1

2

Swapping the first and the last climber is the optimal way to make the sequence of heights first increasing and then decreasing.

예제 입력 2

5
4 3 2 1 5

예제 출력 2

4

예제 입력 3

4
1 2 4 3

예제 출력 3

0

예제 입력 4

10
1 2 7 4 5 6 3 8 9 10

예제 출력 4

2

노트

출처

ICPC > Regionals > Europe > Northwestern European Regional Contest > NWERC 2025 G번

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

출처

대학교 대회

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

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