포럼
문제 ICPC00233

G. Group Photo

설명

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
출력
2
예제 2
입력
5
4 3 2 1 5
출력
4
예제 3
입력
4
1 2 4 3
출력
0
예제 4
입력
10
1 2 7 4 5 6 3 8 9 10
출력
2
문제 정보

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

출처 ICPC NWERC 2025

평가 및 의견

G. Group Photo

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

Log in to rate problems.

개별 의견

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

풀이 제출

G. Group Photo

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