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

32450번 - Business Magic 다국어

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

문제

There are $n$ stores located along a street, numbered from 1ドル$ to $n$ from nearest to farthest. Last month, the store $k$ had a net profit of $r_k$. If $r_k$ is positive, it represents a proft of $r_k$ dollars; if $r_k$ is negative, it represents a loss of $-r_k$ dollars.

As a master of business magic, you have two types of spells at your disposal that you can use to alter the net profts of these stores for the next month:

  1. Blue Magic: You can choose a single continuous interval $[L, R]$. The effect of this spell will be to double the net profit of every store from store $L$ to store $R$ (inclusive) for the next month. That is, if $k \in [L, R],ドル then store $k$ will have net profit 2ドルr_k$ next month.
  2. Green Magic: You can choose any store and cast the green magic on it. The effect of the green magic is to change the next month’s net profit of that store to the negative of its last month’s net profit.

Any store that has not been affected by either spell will have the same net profit next month as it did last month.

However, there are some restrictions when casting spells. You can only cast the blue magic once and it must be used before the green magic. Additionally, the green magic cannot be cast on any store that has already been affected by the blue magic. Your task is to determine the maximum possible sum of the net profits for all stores for the next month after casting your spells optimally.

입력

The first line contains an integer $n,ドル the number of stores. The second line contains $n$ space-separated integers $r_1, r_2, \dots ,r_n,ドル where $r_k$ is the net profit of store $k$ last month.

출력

Output a single integer, the maximum possible total net profit of all stores for the next month after casting the spells optimally.

제한

  • 1ドル ≤ n ≤ 3 \times 10^5$
  • $-10^9 ≤ r_k ≤ 10^9$ for $k \in \{1, 2,\dots ,n\}$

예제 입력 1

5
-2 5 -3 4 -1

예제 출력 1

20

예제 입력 2

7
-1 -1 -1 -1 -1 -1 -1

예제 출력 2

7

예제 입력 3

4
998244353 864197532 -7 1000000000

예제 출력 3

5724883756

힌트

출처

ICPC > Regionals > Asia Pacific > Taiwan > Taiwan Online Programming Contest > TOPC 2024 B번

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

출처

대학교 대회

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

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