結果
| 問題 | No.1433 Two color sequence | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2021-03-26 06:29:26 | 
| 言語 | PyPy3 (7.3.15) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 135 ms / 2,000 ms | 
| コード長 | 352 bytes | 
| コンパイル時間 | 176 ms | 
| コンパイル使用メモリ | 82,176 KB | 
| 実行使用メモリ | 131,092 KB | 
| 最終ジャッジ日時 | 2024-11-27 16:20:43 | 
| 合計ジャッジ時間 | 4,881 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 21 | 
ソースコード
N=int(input())
S=input().rstrip()
A=list(map(int, input().split()))
B=[]
for i in range(N):
    if S[i]=="R":
        B.append(A[i])
    else:
        B.append(-A[i])
S=[0]
for b in B:
    S.append(S[-1]+b)
m,M=0,0
res=0
for s in S:
    if s>=0:
        res=max(s-m,res)
    else:
        res=max(M-s,res)
    m=min(s,m)
    M=max(s,M)
print(res)
            
            
            
        