結果

問題 No.1433 Two color sequence
コンテスト
ユーザー H20
提出日時 2021-03-19 21:56:55
言語 PyPy3
(7.3.23 + ACL)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 68 ms / 2,000 ms
+ 426µs
コード長 621 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 67 ms
コンパイル使用メモリ 82,028 KB
実行使用メモリ 120,028 KB
最終ジャッジ日時 2026-09-26 01:53:02
合計ジャッジ時間 3,784 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

def maxSum(arr):

  cur_max = glob_max = float('-inf')
  glob_start = glob_end = cur_start = -1

  for index, item in enumerate(arr):

    if item > cur_max + item:
      cur_max = item
      cur_start = index
    else:
      cur_max += item

    if cur_max > glob_max:
      glob_max = cur_max
      glob_start = cur_start
      glob_end = index
  return arr[glob_start:glob_end+1]

N = int(input())
S = input()
A = list(map(int, input().split())) 
R = [0]*N
B = [0]*N
for i in range(N):
    if S[i]=='R':
        A[i]=-A[i]
ans = sum(maxSum(A))
for i in range(N):
    A[i]=-A[i]
ans = max(ans,sum(maxSum(A)))
print(ans)
0