結果

問題 No.1433 Two color sequence
ユーザー 👑 SPD_9X2SPD_9X2
提出日時 2021-03-19 21:53:52
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 131 ms / 2,000 ms
コード長 584 bytes
コンパイル時間 234 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 99,968 KB
最終ジャッジ日時 2024-04-29 16:40:27
合計ジャッジ時間 3,795 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
51,456 KB
testcase_01 AC 46 ms
51,456 KB
testcase_02 AC 41 ms
51,712 KB
testcase_03 AC 97 ms
99,584 KB
testcase_04 AC 95 ms
99,456 KB
testcase_05 AC 41 ms
51,712 KB
testcase_06 AC 41 ms
51,584 KB
testcase_07 AC 40 ms
51,584 KB
testcase_08 AC 115 ms
98,864 KB
testcase_09 AC 131 ms
98,544 KB
testcase_10 AC 129 ms
99,712 KB
testcase_11 AC 127 ms
99,968 KB
testcase_12 AC 127 ms
98,796 KB
testcase_13 AC 128 ms
98,544 KB
testcase_14 AC 126 ms
99,024 KB
testcase_15 AC 124 ms
99,024 KB
testcase_16 AC 122 ms
98,756 KB
testcase_17 AC 127 ms
99,144 KB
testcase_18 AC 126 ms
98,752 KB
testcase_19 AC 126 ms
98,768 KB
testcase_20 AC 123 ms
99,020 KB
testcase_21 AC 127 ms
99,532 KB
testcase_22 AC 128 ms
98,888 KB
testcase_23 AC 124 ms
99,020 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

"""

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