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

28318번 - Real Mountains 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
5 초 1024 MB45272068.966%

문제

Thanks to your help with cropping her picture, Rebecca's scenic photo is now featured on the front cover of the newest issue of her magazine. However, it seems that some of her readers still aren't pleased with the picture. In particular, they seem to believe that the mountain in the picture is fake!

For simplicity, we can describe the picture as a sequence of $N$ columns of pixels. In the $i$-th column, the first $h_i$ pixels from the bottom are of mountains. Her readers will only believe that the picture contains a real mountain if it contains a single (possibly wide) peak. That is, if there exists some index $p$ with 1ドル \le p \le N$ such that $h_1 \le h_2 \le \ldots \le h_p \ge \ldots \ge h_{N-1} \ge h_{N}$.

Luckily, Rebecca can still pay her editors to modify the picture and reprint the magazine. Unfortunately for her though, the editors have a very peculiar pricing scheme for their work. The only way Rebecca can edit the picture is by sending emails to her editors containing the integers $(i, j, k)$ such that 1ドル \le i < j < k \le N$ and $h_i> h_j< h_k$. The editors will then add an extra pixel of mountains in the $j$-th column (i.e. increment $h_j$ by 1ドル$) for a cost of $h_i+ h_j+ h_k$ cents. Note that the change in $h_j$ may affect the costs of future edits.

To please her readers, Rebecca would like to edit the picture so that they believe it contains a real mountain. Can you tell her the minimum cost required to do so?

입력

The first line of input contains an integer $N$.

The second line of input contains $N$ space-separated integers $h_1, h_2, \ldots , h_N$.

출력

Output the remainder of $T$ divided by the prime number 10ドル^6+ 3$ where $T$ is the minimum cost (in cents) that Rebecca would need to incur in order to please her readers.

제한

  • 3ドル \le N \le 10^6$
  • 1ドル \le h_i \le 10^9$

예제 입력 1

8
3 2 4 5 4 1 2 1

예제 출력 1

14

힌트

Rebecca can send two emails, the first containing the integers $(2, 6, 7)$ and the second containing the integers $(1, 2, 5)$. The first email costs 5ドル$ cents and increases $h_6$ by 1ドル,ドル while the second email costs 9ドル$ cents and increases $h_2$ by 1ドル$.

The $h_i$ values in the final picture will be $[3, 3, 4, 5, 4, 2, 2, 1]$. Her readers will believe this final picture contains a real mountain.

출처

Olympiad > Canadian Computing Competition & Olympiad > 2023 > CCO 2023 2번

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

출처

대학교 대회

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

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