結果

問題 No.1433 Two color sequence
ユーザー convexineqconvexineq
提出日時 2021-03-19 21:55:54
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 126 ms / 2,000 ms
コード長 370 bytes
コンパイル時間 283 ms
コンパイル使用メモリ 82,312 KB
実行使用メモリ 108,808 KB
最終ジャッジ日時 2024-11-18 22:07:51
合計ジャッジ時間 3,811 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

def Kadane(a):
   v = -1<<60 # i を右端とする区間和のmax
   m = -1<<60 # max(v0,...,vi)
   for ai in a:
       v = max(v+ai,ai)
       m = max(m,v)
   return m

n = int(input())
s = input()
*a, = map(int,input().split())
for i in range(n):
    if s[i]=="B": a[i] = -a[i]
x = abs(Kadane(a))
for i in range(n):
    a[i] = -a[i]
y = abs(Kadane(a))
print(max(x,y))
0