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

31652번 - Minimum Sum of Maximums 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 1024 MB107666.667%

문제

Bessie has $N$ (2ドル\le N\le 300$) tiles in a line with ugliness values $a_1, a_2, \dots, a_N$ in that order (1ドル\le a_i\le 10^6$). $K$ (0ドル\le K\le \min(N,6)$) of the tiles are stuck in place; specifically, those at indices $x_1,\dots, x_K$ (1ドル\le x_1 < x_2<\dots< x_K\le N$).

Bessie wants to minimize the total ugliness of the tiles, which is defined as the sum of the maximum ugliness over every consecutive pair of tiles; that is, $\sum_{i=1}^{N-1}\max(a_i,a_{i+1})$. She is allowed to perform the following operation any number of times: choose two tiles, neither of which are stuck in place, and swap them.

Determine the minimum possible total ugliness Bessie can achieve if she performs operations optimally.

입력

The first line contains $N$ and $K$.

The next line contains $a_1,\dots,a_N$.

The next line contains the $K$ indices $x_1,\dots,x_K$.

출력

Output the minimum possible total ugliness.

제한

예제 입력 1

3 0
1 100 10

예제 출력 1

110

Bessie can swap the second and third tiles so that $a=[1,10,100],ドル achieving total ugliness $\max(1,10)+\max(10,100)=110$. Alternatively, she could swap the first and second tiles so that $a=[100,1,10],ドル also achieving total ugliness $\max(100,1)+\max(1,10)=110$.

예제 입력 2

3 1
1 100 10
3

예제 출력 2

110

Bessie could swap the first and second tiles so that $a=[100,1,10],ドル achieving total ugliness $\max(100,1)+\max(1,10)=110$.

예제 입력 3

3 1
1 100 10
2

예제 출력 3

200

The initial total ugliness of the tiles is $\max(1,100)+\max(100,10)=200$. Bessie is only allowed to swap the first and third tiles, which does not allow her to reduce the total ugliness.

예제 입력 4

4 2
1 3 2 4
2 3

예제 출력 4

9

힌트

출처

Olympiad > USA Computing Olympiad > 2023-2024 Season > USACO 2024 February Contest > Platinum 2번

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

출처

대학교 대회

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

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