結果
問題 | No.1433 Two color sequence |
ユーザー |
![]() |
提出日時 | 2021-03-19 21:56:55 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 110 ms / 2,000 ms |
コード長 | 621 bytes |
コンパイル時間 | 204 ms |
コンパイル使用メモリ | 82,976 KB |
実行使用メモリ | 104,412 KB |
最終ジャッジ日時 | 2024-11-18 22:09:54 |
合計ジャッジ時間 | 3,652 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 21 |
ソースコード
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)