結果

問題 No.1433 Two color sequence
コンテスト
ユーザー 👑 SPD_9X2
提出日時 2021-03-19 21:53:52
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 86 ms / 2,000 ms
コード長 584 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 146 ms
コンパイル使用メモリ 85,248 KB
実行使用メモリ 112,000 KB
最終ジャッジ日時 2026-05-13 08:29:27
合計ジャッジ時間 2,923 ms
ジャッジサーバーID
(参考情報)
judge1_1 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

"""

Rの総和
Bの総和

で、R,B 片方が正・もう片方が負の寄与


"""

import sys
from sys import stdin

N = int(stdin.readline())
n = N
S = stdin.readline()[:-1]

a = list(map(int,stdin.readline().split()))

nmin = 0
now = 0
ans = 0

for i in range(n):

    if S[i] == "R":
        now += a[i]
    else:
        now -= a[i]

    ans = max(ans , now - nmin)
    nmin = min(nmin,now)

nmin = 0
now = 0
    
for i in range(n):

    if S[i] == "R":
        now -= a[i]
    else:
        now += a[i]

    ans = max(ans , now - nmin)
    nmin = min(nmin,now)

print (ans)
0